Prefab pools
Now that we have a system that can handle multiple Prefab pools automatically, the only thing left is to define the behavior of the pools. As mentioned previously, we will want the PrefabPool class to maintain two data structures: one for active (spawned) objects that have been instantiated from the given Prefab and another for inactive (despawned) objects.
Technically, the PrefabPoolingSystem class already maintains a map of which Prefab is governed by which PrefabPool, so we can actually save a little memory by making the PrefabPool class dependent upon the PrefabPoolingSystem class to give it the reference to the Prefab it is managing. Consequently, the two data structures would be the only member variables PrefabPool needs ...
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