OnApplicationQuit not called when in the background

I just run into a slight problem with iOS4. It seems OnApplicationQuit is not called if the user shuts down the app when it’s running in the background. This is pretty understandable, but the problem is that I use OnApplicationQuit to save the game’s state so that the user can easily continue from where he left of the last time. Obviously this is not the optimal solution anymore. So,

  1. Is there a way to call a function when the application is quit on the background?

  2. Is there a way to a call a function when the game is moved to the background?

  3. Any other way around this than a manual save?

Which version of Unity do you use?

OnApplicationPause is called with appropriate parameter when the game goes to the background or foreground.

Yes, I figured that out eventually. I didn’t think there was an out of the box solution since IIRC, iOS4 beta wasn’t even out when the 1.6 version I’m using was released. Do you employ seers or did I just remember incorrectly?

Im using unity 2.6 and OnApplicationPause dont work.
The monobehaviour is not called in the editor, neither in web and standalone players.

I put the application in “runningInBackground == true”, and nothing happens…

if you tell it to run in background it will never pause out of unity’s view.

you need to tell it to not run to have it pause when it loses focus

I did it, and it dont work.

If I try to put Application.runInbackground = false the application pauses naturaly while in background but dont starts the OnApplicationPause event.

Some time ago ( 2 weeks more or less) I read in this forum that the event OnApplicationPause needs Application.runInbackground = true.

The guides of Unity have no reference to all of this…

I solved my problem with the solution that follow:

Application.runInbackground = false, the application pauses naturaly while in background.

When the game come out to foreground, I capture the OnApplicationPause event and call the MyPause() method.

It works fine.

Thanks for all.

thats how it should be done :slight_smile:
glad it works :smile:

Hello,

I am using Unity 3.3 and the OnApplicationQuit is not being called at least for the iphone platform. This is a big problem because I am saving variables and releasing memory on those functions. Is this an already known bug? Has anyone fixed it?