Wednesday, June 22, 2011

Unity3D integrated with Android Apps: Can't restart the game.

This is not a resolution post. I'm just talking about what I meet these days.

Integrating Unity3D into Android Apps really painful to me. As I talked few weeks ago, we are using a raw Activity instead of the on inside UnityPlayer class. But today I found that if we don't quit the game by using a.quit(), the game will keep in its status when leaving the activity, even if you create a new activity intent to enter it again.

Remember why I can't use a.quit()? It will quit the whole application, not only Unity game itself.

OK, some people may say, this is good, what I need is just let the game be there and continue to play next time player enter it.

But that's not what I need, instead, I want it restart every time re-enter the game.

What I can do now, is reset all values to initial status when leaving the game, and next time entering, it will looks like a new game.

I really hope Unity3D can give us more options when developing games in Android.


  1. Hi, I'm trying to do the same thing. Maybe it's possible to use Unity's method Application.LoadLevel... But I don't know how to let the Unity part of the game know that it has to use that method... I mean is there a way to do that at all - somehow pass data from Android-side to Unity-side of the app?

  2. Hi Haputka, thank you for your comment. But I'm sorry to say it's a bit long time since I was trying to do this. Finally our project is running into 2 android apps, when we need the game, we will call the game app in another app, and when finished, the game app will exit completely and goes back to the main app.

    I've removed all the code about resetting the game in Unity3D, so sorry again that I can't help you a lot. But in my remember, I was using something like 'get focus' method in Unity3D to let the game know the main app is going to the game activity again.

    Hope this would help you, Thank you again for focusing my blog.

  3. Hi! Thank you for your quick answer! On the subject: I'm looking into the UnitySendMessage() method of the UnityPlayer class. Will try it today. And, by the way, thanks for your post about replacing UnityPlayerActivity class, it helped a lot!

  4. Love never dies a natural death. It dies because we don't know how to replenish its source. It dies of blindness and errors and betrayals. It dies of illness and wounds; it dies of weariness, of witherings, of tarnishings. Love Sms Love Text