Search Unity

Bool Application.isQuitting or something similar

Discussion in 'Scripting' started by Johannski, Feb 12, 2016.

  1. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    I would like to see a bool Application.isQuitting
    Why I think this bool is necessary:
    I use OnDestroy and OnDisable quite often, but the functionality sometimes differs if the script gets destroyed due to an application quit. Sadly OnApplicationQuit gets called after OnDisable and after OnDestroy, so I'm not able to create some global bool myself. Even if I would streamline the process of quitting the application in which I would set a bool value, I still wouldn't handle the editor play button possibility of quitting.

    As for my knowledge I think there is no clean way to solve that problem, please correct me if you know one. I'm also interested in your thoughts, would you need the bool?

    Best regards,
    Johannski
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    The manual execution order graph is a liar.

    Code (csharp):
    1. public class TestScript : MonoBehaviour {
    2.  
    3.     private bool isQuitting;
    4.  
    5.     private void OnApplicationQuit() {
    6.         isQuitting = true;
    7.     }
    8.  
    9.     void OnDestroy() {
    10.         Debug.Log("is quitting on Destroy: " + isQuitting); //prints true
    11.     }
    12. }
     
    Johannski likes this.
  3. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Oh it is? Hm, okay cool... maybe I should have tried that first, but I trusted too much in the documentation :D

    Thanks a lot!

    So then my wish for unity is to refresh the otherwise great ExecutionOrder graphic

    Edit: I just enced up at the graphic again, and just saw that Unity updated it. Thanks a lot, really appreciated that you take even such small threads seriously!
     
    Last edited: May 13, 2016