Instance prespawning
Since we are using GameObject.Instantiate() whenever the PrefabPool has run out of despawned instances, this system does not completely rid us of runtime object instantiation, hence heap memory allocation. It's important to prespawn the expected number of instances that we will need during the lifetime of the current scene so that we minimize or remove the need to instantiate more during runtime.
Note that we shouldn't prespawn too many objects. It would be wasteful to prespawn 100 explosion particle effects if the most we will ever expect to see in the scene at any given time is three or four. Conversely, spawning too few instances will cause excessive runtime memory allocations, and the goal of this system is to push ...
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