OnApplicationPause not working in the Editor?

Is OnApplicationPause not being called in the Editor? Then how can I detect a pause in a way that is also testable in the Editor?

I use OnApplicationFocus. This works on device and in editor.

4 Likes

I’ve tried that, but the problem with that is that this triggers as soon as the focus moves away form the Game view (for example when I click in the Inspector while still in play mode) - I just want to know when it’s paused. (Because I need to detect when the stupid Oculus integration pauses the application when you take off the headset - though it only seems to be doing that in a build, not in the Editor to make things even more interesting… :/)

1 Like

OnApplicationPause should work in the editor. There’s a setting that may affect that (which is shared among different platforms).

The setting is called “Run in background” (see this link for more info: https://docs.unity3d.com/Manual/class-PlayerSettingsStandalone.html)

The checkbox to set it doesn’t appear in every platform, but its value is used in the editor as well. If you uncheck it, the editor will stop running the game when in the background, and should resume when returning to the Unity editor.

It should then call the OnApplicationPause method.

7 Likes

Forget what you been told, just use the proper solution:

Unity 2017
https://docs.unity3d.com/ScriptReference/EditorApplication-pauseStateChanged.html

Unity 5.6.x
https://docs.unity3d.com/560/Documentation/ScriptReference/EditorApplication-playmodeStateChanged.html

1 Like

Thanks liortal, it’s work.