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?

1 Answer

1

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 ExecuteInEditMode 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 instead.