- Home /
OnApplicationPause is not working correctly in Unity 5.
I upgraded my project from unity 4.5 to unity 5.0. And i am experiencing the abnormal behavior of OnApplicationPause method of unity. I have the following code.
void OnApplicationPause (bool pauseStatus)
{
if (pauseStatus)
print ("Application Paused");
else
print ("Application Resume");
}
It never print Application Paused when I switch out from unity editor but it print Application Resume when i switch back to unity editor. this works fine in Unity 4.5.
Have the same problem, did you find a workaround for this problem?
Answer by ocimum · Sep 02, 2015 at 03:16 PM
Looks to me like it could be the fixed issue discovered in version 5.1.xxx
Maybe you upgrade to a higher or stay on Unity 4.5 if you need lower versions because of maintaining your projects.
Found a solution for me. It was 'run in background' enabled checkbox. http://answers.unity3d.com/questions/9899/how-do-you-keep-your-game-running-even-when-you-sw.html
<3 you Andrew! what are the chances you supply this data 2 days before I go searching for it! Thanks for posting your solution.
@Andrey Postelzhuk Hmm I tried to implement this for the Iphone with the "Requires Fullscreen" bool unchecked since there is no "run in background" bool. It does not seem to be calling OnApplicationPause function:
void OnApplicationPause(bool pauseStatus){
if(pauseStatus){
SetChallengerStatus (0);
}
}
So I got it working on iphone by setting the "Behavior in Background" list to Custom. This option is found in player settings => other settings => configuration.
"Requires Fullscreen" bool must also be set to false.