I’ve spend the better part of this week working on optimizing the game to run much smoother. It’s incredible how many things you can find in your code to improve if you really look for them. When I went in to this I had only one real thing in mind, that was to implement object pooling (I’ll describe this in a second) but once I got started I realized that no one thing was going to give me the dramatic performance boost I wanted. As a result I spent hours and hours finding where the bottlenecks were and how to fix them and learned a lot of cool things that will carry over into future projects 😀
After some digging on the Unity forums I found out about a best practice known as object pooling. You see in my game (and most games) there is a lot of creating and destroying of objects. You have to do this with modular level pieces, projectiles, particle effects, and basically anything that isn’t constantly present. Previously how I handled this was to just create them and destroy them. This works fine but since things are constantly being added and removed from memory it can cause the garbage collector to fire often and cause slight jitters in the game.
Instead of adding and deleting objects you simply create a “pool” of them. When you need one you pull if from the pool, activate it, and put it where you need it. Then when you’re done you disable it and add it back to the pool.
Although this is helpful it has the disadvantage of a longer level load time since all objects have to be created at the start of the scene.
Once I was mostly satisfied with the performance I went on to implement a few very important aspects of the game content itself.
First I created fly-out announcements. Basically just text that fly’s out when you pick up a powerup. This is important since the game is centered around humor and if you don’t know what the powerup is you will not get the joke. I haven’t yet decided if I want these to fire the first time you get the powerup or every time.
Next I added an in-game tutorial which will always appear until you complete it. It pauses the game and gives you instructions for each type of obstacle. It’s very simple but effective.
The last change I made was to implement a sort of animated comic that gives a bit of simple storyline behind the game. It’s not flashy and reflects my underdeveloped art/animation skills but it gets the point across. Seeing as this is something people will probably see only once if at all I think it is sufficient for now.