Fundamentals:

by

Game Maker here. I use Unity myself, but these tips are some universal techniques that any programmer can use. Memory Management and optimization: most engines have garbage collection to free memory back up, since if there is too much garbage it can lower framerate. Creating and destroying objects yourself is very inefficient, but I found a technique that can lead to a fun little weekend project: object pools. An object pool is a collection of objects held in a group that can be positioned and activated, and then upon completion, hidden and reset back into the pool. Don’t be discouraged; starting out with object pools just involves creating and destroying objects, which can be a fun little project. I also recommend the 2D Extras asset from the asset store, it has smart tiles and animated tiles, it’s old but essential for a 2D tilemap game.

Anyway an example of a good object pool is creating the pool object with a C# script that instantiates the prefabs that also have a separate script. Then storing them in an array or list, tracking their state or their starts, selecting inactive objects for use, and automatically resetting the pool object, be it explosion FX, or bullet or particle effect. You can anticipate the maximum number of objects in a pool array, or with a list, add objects as needed that destroy themselves if they’re not being used. An object pool is great for particle FX, once you can build a good efficient object pool of FX and constantly reused objects you are well on your way to building fun, customized game code.
If you’re just starting don’t even worry about it, just instantiate and destroy, don’t use destroy immediate. A quick tip I’ll cover later is use a game manager script to track status, and a sound management object.


Read the rest