Skip to content

IPoolable

Andrés Eduardo Maldonado edited this page Jun 14, 2019 · 4 revisions

Public interface.

Description

Interface with events from the Pooling System, use this if you want to execute code at spawn/unspawn from the pool.

NOTE: IPoolable should be used by a MonoBehaviour (or a child of) and preferably be on the root of the prefab.

Usage

public class ExampleScript : MonoBehaviour, IPoolable
{
    private int counter;

    public void OnPoolSpawn()
    {
        counter++;
        Debug.Log("I've been spawned " + counter + "times!");
    }

    public void OnPoolUnSpawn()
    {
        // Other events here.
    }
}

Methods

Returns Name Description
void OnPoolSpawn Called when the object is taken out from the pool.
void OnPoolUnSpawn Called before the object needs to go back to the pool.