- Home /
How do I optimize memory footprint of multiple pools of similar GameObjects?
Hi guys!
I've been working on a Unity game on the iOS that I need to introduce some new elements to. We use the pooling technique to improve the speed at which objects are created and destroyed by not having to call instantiate, but instead simply pulling from and pushing the GameObjects back into a pool. However, this has memory ramifications that mobile games must watch, though we've managed to toe the line so far.
However, new design requirements have come up that threaten to overtop our memory limits. The game's GameObjects are managed via prefabs, as you may expect, and the pool manager instantiates a certain number of the prefab on load. Say...
20 of Enemy A prefab
20 of Enemy B prefab
20 of Enemy C prefab
100 of Projectile prefab
However, the new design wants to introduce the concept of different kinds of projectiles and enemies, which, if we stick to the current method, doubles or triples the pool's memory footprint, which is unacceptable.
The regular way to tackle this issue in a from-scratch game is simply to have a base Projectile class that gets customised to different kinds when created from the pool. One simple saves the customised behaviour and variables either in crude spaghetti switch codes or scripts or xml or what-have-you, and it switches on runtime based on, say, a single "ProjectileType" variable, so the pool memory footprint remains the same even if there are 200 different kinds of projectiles.
My question is how do you replicate this technique in Unity with prefabs while still maintaining the ease for the designer tweaking the prefabs within the inspector? I could have a Projectile prefab that I change values and textures on object "creation", but that seems to defeat the purpose of prefabs in the first place.
Thank you!