- Home /
How do I detect if game is in play or edit mode?
I want it so that when the object is in play mode, it will have a different material compared to the one in edit mode. How can I achieve that?
Answer by Molix · Apr 13, 2011 at 01:42 PM
The Application class has a few items that might be of interest, Application.isPlaying, and Application.isEditor. Of course, you could just change the material from the editor one to the play one in Start(), too.
If you need to check which mode you're in, you probably used the ExecuteInEdit$$anonymous$$ode attribute. In that case, Start() runs in both edit mode and play mode.
Note that Application.isEditor is still TRUE when in play mode. This is because you are technically using the editor to view your game in play mode. Application.isPlaying changes from false to true on entering play mode. This is the reason there are 2 separate variable.
Application.isPlaying
and EditorApplication.isPlaying
will return false when entering the Play mode from Editor if used in in static constructor in class with [InitializeOnLoad] though. You need to use EditorApplication.isPlayingOrWillChangePlaymode
in this case ins$$anonymous$$d.
Your answer
Follow this Question
Related Questions
centerOfMass not in edit mode? 2 Answers
play mode error 1 Answer
Do I need ExecuteInEditMode() for all scripts? 1 Answer
Running a script in editor mode 2 Answers
CombineChildren not working under ExecuteInEditMode() 1 Answer