- Home /
How do I get OnApplicationPause to trigger?
When I run my project in the editor I first get a call to OnApplicationPause with false which seems ok. But when pressing the pause-button in the editor I don't get any call to OnApplicationPause. I expected a call with true this time.
Do I have to have "Run in background" unchecked for this to work?
The problem I'm having with that is that the checkbox keeps check itself whenever I run the project, then go back to unchecked again when I stop it.
I'm using Unity 4.6.2
I tried this and you're right, it's not called. I recommend you to file a bug report on this (Unity -> Help -> Report a Bug). Seems there was once a "resume" function but is not anymore. $$anonymous$$aybe they screwed something up when they switched to that single function.
Answer by Fattie · Jan 26, 2016 at 01:33 AM
Simply
CLICK ON THE DESKTOP OF YOUR MAC OR PC
it's that simple.
THAT DOESN'T WOR$$anonymous$$, BOOOOOO! https://issuetracker.unity3d.com/issues/onapplicationpause-doesnt-get-called-when-switching-from-editor-to-another-application It's that simple, a failed fix!
hey bra - (1) are you on a $$anonymous$$ac? (2) exactly what version of Unity?
Sure, this tip is a year old - that's 25 years in dog computer years
You also have to have Run in Background unchecked
Answer by instruct9r · Feb 12, 2015 at 11:32 AM
OnApplicationPause is not going to be called, if you pause the project in Unity simply because, when you pause it, everything in your game pauses. When running the game in the editor press ALT + TAB, to switch to another window, or just minimize Unity down and then reveal it again. This way the application continues to work and it knows that it was pulled down. If you pause the editor, everything pauses and there is no way, that the code knows, if it was paused...
Doesn't make sense to me since a boolean parameter is supposed to have 2 values. If that wasn't an option, why even have that? For ALT + TAB there's $$anonymous$$onoBehaviour.OnApplicationFocus
OnApplicationPause is called, when the application is paused by the system (Not by the editor). So if you run a game on iPhone and while playing you press the home button, OnApplicationPause will be called with pauseState = true. When you run the game again, OnApplicationPause will be called with pauseState = false.
There is no need for Unity to call OnApplicationPause, if you pause the game in the editor, simply because it will be useless. Pausing in editor is for debugging, not for calling functions.
Or maybe i don't undestand what you need to achieve? If you are trying to make the application to call OnAPplicationPause, when it's pulled down, then this is the function that you need to call
I just assumed that the "pause"-button in the editor should call "OnApplicationPause". It seemed logical. But if not, how do I then debug this behaviour without deploying on a real device?
Put this code in some script in your game:
void OnApplicationPause (bool : pauseState)
{
print (pauseState);
}
Now run the game in the editor and while running $$anonymous$$imize unity (Or just reveal some other window) and then maximize again. You will see the 2 states in the console (true and false).
Your answer
Follow this Question
Related Questions
Header attribute and Custom Property Drawer overlap in inspector, repeat header text 2 Answers
Unity Editor 'actively refused' attaching debugger 4 Answers
Add same go as a child to multiple gameObjects in hierarchy 0 Answers
Set MinWidth for EditorWindow 1 Answer
Why my Roguelike 2D graphics are naughty in devices? 1 Answer