Search Unity

OnApplicationPause not working in the Editor?

Discussion in 'Editor & General Support' started by col000r, Sep 14, 2016.

  1. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    699
    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?
     
  2. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    I use OnApplicationFocus. This works on device and in editor.
     
  3. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    699
    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... :/)
     
    Miscellaneous likes this.
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    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.
     
  5. Miscellaneous

    Miscellaneous

    Joined:
    Sep 24, 2013
    Posts:
    53
    eelstork likes this.
  6. pd302302

    pd302302

    Joined:
    Feb 13, 2022
    Posts:
    1
    Thanks liortal, it's work.