Poolable Components

Let's first define an interface class for a Component that can be used in the Pooling System:

public interface IPoolableComponent {  void Spawned();  void Despawned();}

The approach for IPoolableComponent will be very different from the approach taken for IPoolableObject. The objects being created this time are GameObjects, which are a lot trickier to work with than standard objects because of how much of their runtime behavior is already handled through the Unity Engine and how little low-level access we have to it.

GameObjects do not give us access to an equivalent New() method that we can invoke any time the object is created, and we cannot derive from the GameObject class in order to implement one. GameObjects are created ...

Get Unity 2017 Game Optimization - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.