Search Unity

function OnApplicationQuit dosn't work

Discussion in 'Editor & General Support' started by simom85, Nov 24, 2011.

  1. simom85

    simom85

    Joined:
    May 27, 2010
    Posts:
    283
    Hi boys! I noticed that OnApplicationQuit only work when I stop the game in Editor while nothing happens if a close the browser with the webplayer!

    I have to update the SQL database deleting a value when the game is closed

    repat: in Editor everything work good!


    The documetation say: In the web player it is called when the web view is closed

    Is it a bug?
     
    Last edited: Nov 25, 2011
  2. simom85

    simom85

    Joined:
    May 27, 2010
    Posts:
    283
    please
     
  3. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    699
    I never got it to work, please report a bug!
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    it works correctly where its meant to work but:

    1. On webplayers you can't rely on it. if the browser 'kills' plugins upon tab / window close you will not get any time to execute anything. You should consider doing it on the javascript side of the page which might get 'more time' than the plugin which exists in a whole different, seperate layer
    2. The editor does not respect OnApplicationQuit, when you end play mode it end.. There is no 'quitting' cause the editor just terminates the Play Thread, it does not 'quit an application'. The function might execute but it will not be given a 'time slice', stuff that is not immediate will likely never perform (WWW for example)

    On all other platforms it works within the platform declared limitations (for example you don't have all eternity time in there on iOS)
     
  5. DaveA

    DaveA

    Joined:
    Apr 15, 2009
    Posts:
    310
    I used OnDestroy in my 'main' script, which is close to the same thing, but will fire I think. But like dremora says, it's just 'more time'. I signal out to the containing page to send my final update via standard AJAX but no guarantee. You can do tricks like use HTML frames and put that code in another frame, but there's always the possibility that they didn't simply navigate away, but closed the browser.