I’m about to release my first game using GameCenter connectivity. I’ve been using the sandbox to test achivements and leaderboards, but seem to have run into a pretty significant problem. I’ve combed through the forums here but surprisingly haven’t come across this topic.
I am using Unity 3.5.7f6.
Soon after loading the game, I run Social.localUser.Authenticate. At any point after that, the game might get sent to the background (the user presses the button on an iDevice, or the device goes to sleep). Once it’s resumed, it will crash almost immediately.
Unfortunately XCode doesn’t seem to give me a lot of details, and I’m not sure how to better debug this issue. Nothing is actually written to the device log.
Here’s what I have:
→ applicationWillResignActive()
→ applicationDidEnterBackground()
→ applicationWillEnterForeground()
→ applicationDidBecomeActive()
2013-02-27 18:04:54.099 istone[148:707] authenticateWithCompletionHandler: enter
2013-02-27 18:04:54.101 istone[148:707] authenticateWithCompletionHandler: exit
Failed to authenticate local user The requested operation has been cancelled.
Failed to authenticate
Some parts of this error are different depending on if I connected to the sandbox or if I pressed cancel. Either way, the game crashes on resume.
I’m really not doing anything fancy with Social connectivity. No error occurs if I remove Social.localUser.Authenticate but then of course I can’t take advantage of gamecenter’s features.
you don’t actually say why you think the authenticate is causing it. Have you tried commenting it out and seeing what happens?
I’ve got it working on my game that is live and it seems to work so it might be some logic you are doing around the whole authenticate process.
If you want post me your code and I will have a look, my address is social at qedgaming dot com
Thanks for the affirmation that things work fine on your end.
I tried stripping out everything else from the scene where I call Authenticate, and the crashing problem went away.
The problem seems to be tied to an iTween component that I was creating right before the Authenticate function in order to animate some bouncing text. While I’m not entirely sure why this would lead to a crash several scenes later when resuming the game, I’m certainly glad that it doesn’t happen any more.
Ah, I think the mystery is solved. When the game resumes from the background, it appears that it calls the exact same Authenticate function as before. My mistake was putting some logic in the callback pertaining to the current scene (related to the animated text I mentioned earlier).
I’m a bit surprised to see it behave this way since I thought each scene and its scripts were more or less stand-alone. But it makes sense; this way we don’t need an Authenticate function in every scene.
Yes, I always have a dummy first scene that basically sets up all my listeners and starts all my singletons, waits a few seconds then launches te first scene the player sees. The reason I wait a bit is that the unity code that returns the screen size lies about it for a few times round the update loop.