Hello,
I’m currently using Unity 4.3.1 free and I’m experiencing this unwanted behaviour on Android:
if I press the back button at the right moment while a scene is loading the application quits.
Scripts of the new scene reach the Start() and Update(), but before anything appears in the screen the game just closes.
I can’t find anything on my scripts that would do that, so I’m starting to think it could be an Unity issue.
Has anyone else encountered the same thing? I tested this on an S3 mini with Android 4.1.2 and a Nexus 7 with 4.4.2; it’s easier to trigger on the S3 mini because the loading times are longer but it can happen on the N7 too.
I created a very simple test application with two scenes. Each scene contains just some big GUITexture to increase the loading time. There is only a script that on any keypress loads the other scene. If I repeadetly press the back button while it’s loading the application closes. I’m pretty sure it’s an Unity bug now.
This is not a bug, is the intended behaviour on Android apps. You need to override the back button, can do it via native Android plugin or via Unity with Input.GetKeyDown.
Example:
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
return;
}
}
Check which KeyCode is the equivalent to Android back button, I don’t remember if was KeyCode.Escape or some other.
Yes, it’s Escape and I already use that. The game does not close if I press the back button after the loading is completed.
There seems to be a short time window during the loading of a new scene where the behaviour I described happens (the application closes itself).
That’s probably because the gameObject that’s checking Input.GetKeyDown is destroyed when changing scene, you would need to add DontDestroyOnLoad on this gameObject or do it via Android plugin.
Just tried adding a DontDestroyOnLoad script on the first scene and the problem is still there.
Maybe an Android plugin could solve the issue but I’ll try only if nothing else works.
Thanks for the replies anyway