Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Quit editor player on focus lost?

Discussion in 'Editor & General Support' started by Magnesium, Apr 14, 2021.

  1. Magnesium

    Magnesium

    Joined:
    Sep 14, 2014
    Posts:
    179
    Hello,

    About nine times out of ten, i forget to stop the editor player before switching to my code editor. Then i have to wait for Unity to compile the changes, stop the player, restart the player, which is time consuming.

    Is there a way to stop the player whenever the editor loses focus?

    Thanks
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    I think you can just by listening to OnApplicationFocus() and making an editor call to set playback false.

    Obviously you wanna wrap that in
    #if UNITY_EDITOR
    for conditional compile.
     
  3. Magnesium

    Magnesium

    Joined:
    Sep 14, 2014
    Posts:
    179
    Good suggestion. However, this executes whenever the player loses focus so it will exit if i click anywhere in the editor.

    Going through Unity's often poor documentation has driven me crazy for today, i'll give it another try tomorrow and post the code if i find a reliable solution.
     
  4. Isn't stop good enough? I don't understand your problem.
    screenshot1.png
     
    Magnesium likes this.
  5. Magnesium

    Magnesium

    Joined:
    Sep 14, 2014
    Posts:
    179
    I does indeed, i just didn't know the option and didn't find anything (or probably wasn't asking the right question) on Google.

    Thanks!
     
    Lurking-Ninja likes this.