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.

Monday, June 6, 2011

Unity3D 3.3 integrated with Android 3.0 apps (Activity Switch)

Recently when working in a project, I feel painful with the Unity 3.3 integration in Android 3.0.

When I'm trying to go to another activity from UnityPlayerActivity, it will go exiting the whole apps and restart it with Main Activity.

I spent almost a week on it and finally got fix under Ping's help. Thanks Ping.

The problem is based on UnityPlayer class it self, looking into the class jar package, we found this line in onDestory() under UnityPlayer class:

a.quit()

which a is a UnityPlayer instance.


UnityPlayerActivity is extending from UnityPlayer so it surly will exit the app when switching into another activity.

What we did is make our game activity extends from Activity instead of UnityPlayerActivity or UnityPlayer. And using codes inside UnityPlayer to "recreate" a Unity gaming activity, but comment the "a.quit()".

Here's a sample code for the activity, it works fine here now.



However, we are still waiting for a offical fix on 3.4 release from Unity3D.

Thanks Ping again! :D