Object spawning
Let's define what it means to spawn GameObject in the context of our pooling system: at some point, PrefabPool will get a request to spawn GameObject from a given Prefab, at a particular position and rotation. The first thing we should check is whether or not we have any inactive instances of the Prefab. If so, then we can dequeue the next available one from Queue and respawn it. If not, then we need to instantiate a new GameObject from the Prefab using GameObject.Instantiate(). At this moment, we should also create a PoolablePrefabData object to store the GameObject reference and acquire the list of all MonoBehaviours that implement IPoolableComponent that are attached to it.
Either way, we can now activate GameObject, set ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access