Search Unity

Question Event when user is shutdown or logoff

Discussion in 'Scripting' started by Threeyes, Apr 18, 2021.

  1. Threeyes

    Threeyes

    Joined:
    Jun 19, 2014
    Posts:
    80
    It seems that the OnApplication won't get call when user is shutdown or logoff, it there a way to watch there event in unity, so we can ensure things get saved when the app is closed?
     
  2. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    2,198
    Do you have don't destroy on your object that uses it? It might get destroyed before the OnappExit gets called. We use this event in our game and don't have problems with it not being called.
     
  3. Threeyes

    Threeyes

    Joined:
    Jun 19, 2014
    Posts:
    80
    Thanks for replay, but my problem is how to detect the user is shutting down the computer or logoff, it seems that unity won't deal with these system events.
     
  4. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    2,198
    emirpine likes this.
  5. Threeyes

    Threeyes

    Joined:
    Jun 19, 2014
    Posts:
    80
    I tried that example too, but the SystemEvents.SessionEnding don't get fire on Unity, however when I create a WinForm solution, it works fine, so I am confused, wasn't standalone built by Unity a form?
     
    YiHan-GI likes this.