Fixing the Freeze


Hey, this is Weston, the main programmer for this project. Our last post was made in preparation for the release of the minimum viable product version of our game. Unfortunately, the game ran fine in the desktop unity editor, but would freeze and become unplayable when actually run on a phone. This post will be all about this bug and how I fixed it.

At first, I thought this bug was due to one or more of the scripts associated with the new 'bird system' we had added to the game. It seemed like the most likely candidate because it was loading and unloading a fair amount of assets rather quickly and was one of the more complex systems in the game. It was also the only major addition to the game since the previous update where the game ran fine on a phone.

To test this, I began disabling elements one at a time in the scene and exporting a new build to my phone. First I started with the script attached to each bird but that didn't help. Then I tried the script that directs the birds on where to fly and that didn't fix anything either. Finally I disabled the script the spawned the birds all together, effectively removing them from the game. Even with the birds completely removed, the game remained frozen when played on a phone! 

At this point I was a bit stumped. I began disabling each component in the scene until the game ran normally. It seemed like no matter what I did, the game would still be frozen when run on a phone. It wasn't until only the static environment and the player's camera were in the scene that the game would run without freezing! As I began re-enabling each component of the scene to pinpoint the problem, I noticed that it was the UI that seemed the cause the freezing. Even more interestingly, I discovered I could still move the camera in the game as long as it wasn't looking at any UI element in the scene. 

It was a relief to know where the issue was coming from, but I still didn't understand what had changed in the UI between the last build where it didn't cause any problems and the current one. At this point, I was pretty clueless as to what was going on, so I turned to google even though I didn't expect to find an answer. Despite my doubts, the first result gave a direct answer to my problem. As seen here (https://issuetracker.unity3d.com/issues/android-camera-view-freezes-on-canvas-and-mask-group-when-using-cardboard), another user reported a bug that would cause freezing while using masks in his UI .

This fit my problem exactly and would also explain what had changed since the last working build. In the gif attached to this post, you can see how I was using masks to create an animated transition in the UI, which was also the only major change I had made to the UI since the last working build. Much to my relief, when I disabled the masks in the UI, the game became functional again and would even run with the birds as they were before! Hopefully we don't run into any similar game-breaking bugs as we wrap up development.

Leave a comment

Log in with itch.io to leave a comment.