Skip to content
This repository was archived by the owner on Aug 14, 2019. It is now read-only.

ObjectPooler.cs

Erik edited this page Apr 25, 2019 · 4 revisions

Dependencies
Public Methods:
  • GetPooledObject(GameObject go) - Pops a PoolableObject from the Queue or instantiates a new one. Should be used in placed of "Instantiate". The parameter go should be a prefab.
  • ReleasePooledObject(PoolableObject po) - Adds the PoolableObject back to the queue.
Public Events:
  • None
Configurable Fields:
  • prePooledObjects - List of objects and their count that are instantiated and added to the pool on load.
General Overview:

The ObjectPooler maintains a dictionary of queues for each unique prefab. When a prefab instantiation is requested via GetPooledObject(go), the dictionary is first checked for that queue. If the queue exists and at least one object is in the queue, it is popped and returned. Otherwise, a new object is instantiated. The PoolableObject component is added to all objects instantiated via the ObjectPooler. When a PoolableObject is disabled, it is added back to the queue for reuse.

Clone this wiki locally