2

I have a simple game object (the main UI object) with OnApplicationPause that prints out the Pause status (true/false) in the debug log. When I run it on android, and press the Home Button to leave the app, I see that the OnApplicationPause() is called twice in a row, with the same pauseStatus (true). The same happens when I reopen the app: the OnApplicationPause is called twice with Pause status false.

Why is it being called twice and can I avoid it? Am I doing anything wrong?

I also tried to create a separate GameObject, that includes the same debug code. The issue doesn't occur there - only in my main UI object.

TofuBeer
  • 60,850
  • 18
  • 118
  • 163
Sagi Mann
  • 2,967
  • 6
  • 39
  • 72

1 Answers1

4

Are you 100% sure that your script containing the OnApplicationPause() method is not present twice in the Scene when Pause occurs? or present on a previous Scene on a DontDestroyOnLoad GameObject?

OnApplicationPause is called on each active MonoBehaviour when pause occurs.

So having two Debug.Log means two scripts instances running if you don't call it manually yourself.

jlevet
  • 104
  • 9
  • you are correct with that lead: the script was associated to 2 different objects in the scene (not sure why though, the code was coming from a 3rd party unity package, which included this demo scene, objects, script, etc). thanks! – Sagi Mann Jun 23 '15 at 08:32