I am new to unity 3. When I deploy for iOS 4 devices I find there’s a few problems when unity work together with the iOS’s multi-task features. Sometimes the background music is mute and touch control was disable when my game awakes from background process.
I guess it could because some initialization process I did with the Start() function lost its state when I hit the “home” button on iDevice, so they will not resume unless you do it manually again when I awake the game from background.
What is the underline concept for unity engine to handle those background/active swap of game state? Is there any delegate function in unity to be called every time game awakes from background so I can manage some tasks manually by code?
The intention is that Unity should handle multitasking without any special user code. A bug was reported regarding audio muting after an app is brought from the background, but we believed it was fixed. Please can you file a new bug report for this (menu: Help > Report A Bug) and mention that it may be a recurrence of case 370557. This should help the QA team track down the problem and get it fixed more quickly.
My main concern is that games do not stop immediately the user’s attention has ended by pressing the Home button (this is the way I found about my problem, but it can apply to any multitasking action), and seemingly no way for the developer to act on this step. Also, returning to the game currently brings the player back into the action. Both are undesirable for an action game.
I would like to bring the player back at the point they chose to stop, and in a state where they have the opportunity to assess the situation before continuing. My preference is to be able to immediately pause the game on any action that will take the player away from the game, with them therefore returning in the same pause state.
The OnApplicationPause() event is called before and after the application is moved to the background. You can use it to pause the game when the application is moved to the background. You can also use it to save the game, since OnApplicationQuit is not called if the game is quite while in the background.
OnApplicationPause() is called when the game moves to the background. This is a significant amount of time after the Home button is pressed. In my game it is enough time for the player to die. It also creates discrepancies between the game position and data automatically saved. For example, I can have a new player life generate during the period, but the data was saved before then, so generates another.
iOS has an OnWillResignActive command that as far as I can tell is called at the time of the Home button press, but I do not know how to access this in Unity.
I have the same problem as some people mentioned in your post. After handling the OnApplicationPause() method, I still cannot resolve all crash issues. For some scenes the game will freeze when it is turned off for a relative longer time. But some scenes are fine. I’ve no idea on how to debug this.
For now, I just add UIApplicationExitsOnSuspend to Info.plist to stop the multitasking.