Introduction
Introduction
Welcome to the Runtime Spawner, your solution for dynamic / procedural spawning of AI characters, animals and pedestrians for your Unity games.
The primary goal of this package is to provide a generic spawning system, complete with object pooling. There are many types of games that can benefit from the Runtime Spawner package, and it can be used for a wide variety of use cases including:
Ambient animals / roaming creatures
Pedestrians
Roaming enemies
Waves of enemies / Horde mode attack waves.
What is Object Pooling
To add an object into a scene during your game, the default way of handling this is to call GameObject.Instantiate(); This will dynamically spawn the new object into the scene. This is very easy to do, and one of the first thing you learn when starting to make games with Unity.
However, something that the Unity documentation strangely doesn’t mention is that calling ‘instantiate’ is very expensive (particularly with larger / more complicated prefabs such as animated characters) and may cause frame rate stalls and other performance hits, particularly during action / dynamic moments in your game.
Why is this Important?
One of the easiest ways to avoid these stalls is to use an Object Pool. What this means is that instead of instantiating individual game objects on their own, you instead pre-spawn (or ‘pool’) a number of the objects in advance (say when the level loads) and then instead of calling Instantiate() to spawn the new object, we instead ‘get an object from the pool’. This is a LOT more efficient and performant. The same goes if we are done with the object (say the enemy dies), in this case we don’t Destroy() the object, we instead ‘Return the Instance’ to the pool.
If this sounds confusing, don’t worry! The Runtime Spawner handles all of this (and more) for you automatically!
Last updated