So I’ve released my app, Zombieville USA, on the app store and its doing fairly well so far and getting good reviews, but there’s this periodic framerate hitch that I’ve been trying to track down ever since submission.
The Problem: Basically every few minutes or so, the game will stall briefly (sometimes the stall will last for a fraction of a second, sometimes for a full second or two). Both the visuals and the sound will freeze during this time (especially noticable if there’s a sound effect playing at the same time - it will hang in the middle of playback in a most noticeable way). This stall is then followed by a 5-6 second period of decreased performance overall - the framerate is lowered, and the responsiveness of the touchscreen goes to hell, almost like its recovering from something. In a fast paced action game like mine, this is really annoying, since during this period of decreased performance, the fire button becomes unresponsive. Freshly restarting my test device seems to reduce the intensity/frequency of these stalls and their following period of poor performance, but they always occur eventually.
But wait, there’s more! I first discovered and reported this issue a while back, here’s a link to that thread.
http://forum.unity3d.com/viewtopic.php?p=120927&highlight=#120927
For some strange reason, my game was experiencing this same stall every 15 seconds or so after I added a ‘menu’ level to my project, rather than every few minutes. I ultimately removed the menu level, and simply incorporated its contents into my main game level, which solved the extremely high frequency of the stalls.
So what’s up with my game? These stalls occur regardless of what’s going on on screen - it can be in the thick of battle with a dozen zombies, or just walking down the street with only one enemy on screen. I suspected garbage collection was the source of these issues, so I tried putting a request to run GC at the start of each stage. This seems to have had little or no effect. I also completely re-wrote my zombie spawning system to use a pool of recycled zombies that are always in memory, but hidden off screen until they’re needed, rather than constantly instantiating and destroying them. This helped performance in general, but did not remove the stalls. Overall the game runs pretty well, but this issue is driving me crazy, and seems completely random and out of my control.
I’m going to try sending in a bug report with my project so the Unity folks can pick it apart.