ScriptablePool<T> Class
Definition
Section titled “Definition”A UnityEngine.ScriptableObject that holds a pool of values.
public abstract class ScriptablePool<T> : ScriptablePool, INotifyPropertyChanging, INotifyPropertyChanged, IStackTraceProvider, IPoolCallbacks<T> where T : classType Parameters
Section titled “Type Parameters”T
The type of to pool. Must be a class.
Inheritance object → UnityEngine.Object → UnityEngine.ScriptableObject → RuntimeScriptableObject → ScriptablePool
Implements INotifyPropertyChanging, INotifyPropertyChanged, IStackTraceProvider, IPoolCallbacks<T>
Properties
Section titled “Properties”CountAll
Section titled “CountAll”How many total objects that the pool is keeping track of.
public override sealed int CountAll { get; protected set; }CountActive
Section titled “CountActive”How many objects that are currently active.
public override sealed int CountActive { get; protected set; }CountInactive
Section titled “CountInactive”How many objects that are currently inactive.
public override sealed int CountInactive { get; protected set; }Methods
Section titled “Methods”Gets an object from the pool.
public T Get()Returns
Section titled “Returns”T
The newly acquired object from the pool.
Release(T)
Section titled “Release(T)”Returns an object to the pool.
public void Release(T item)Parameters
Section titled “Parameters”item T
The item to return.
Clear()
Section titled “Clear()”Clears the pool. All objects, both active and inactive, will be destroyed.
public void Clear()CreateObject()
Section titled “CreateObject()”Called when a new object needs to be created.
protected abstract T CreateObject()Returns
Section titled “Returns”T
DestroyObject(T)
Section titled “DestroyObject(T)”Called when an object needs to be destroyed.
protected abstract void DestroyObject(T item)Parameters
Section titled “Parameters”item T
The object to be destroyed.
OnGet(T)
Section titled “OnGet(T)”Called when an object is retrieved from the pool.
protected virtual void OnGet(T item)Parameters
Section titled “Parameters”item T
The object that was retrieved from the pool.
OnReturn(T)
Section titled “OnReturn(T)”Called when an object is returned to the pool.
protected virtual void OnReturn(T item)Parameters
Section titled “Parameters”item T
The object that was returned to the pool.
OnPreStart()
Section titled “OnPreStart()”Called when the game starts, before OnStart().
You should not subscribe to events in this method! Use OnStart() instead. OnPreStart() should be used for preparing the scriptable object.
protected override void OnPreStart()Remarks
Section titled “Remarks”If this isn’t called when the game starts, it’s called once this scriptable object is loaded and instantiated.
OnDisabled()
Section titled “OnDisabled()”Called when the game is ending, after OnPreDisabled().
You should not unsubscribe from events in this method! Use OnPreDisabled() instead. OnDisabled() should be used for cleaning up the scriptable object.
protected override void OnDisabled()Remarks
Section titled “Remarks”This can also be called during the game is the scriptable object is destroyed and/or unloaded.
WarnIfLeftOverSubscribers()
Section titled “WarnIfLeftOverSubscribers()”Warns if there are any left-over subscribers to the events.
protected override void WarnIfLeftOverSubscribers()Remarks
Section titled “Remarks”This will only be called in the Unity editor and builds with the DEBUG flag.
ClearSubscribers(bool)
Section titled “ClearSubscribers(bool)”Removes any subscribers from the event.
public void ClearSubscribers(bool warnIfLeftOver = false)Parameters
Section titled “Parameters”warnIfLeftOver bool
If true, a warning will be printed in the console if there are any subscribers.
The warning will only be printed in the editor and debug builds.
Return(T)
Section titled “Return(T)”[Obsolete("Use 'Release' instead. This will be removed in build.", true)][ExcludeFromCodeCoverage]public void Return(T item)Parameters
Section titled “Parameters”item T
Events
Section titled “Events”OnPoolChanged
Section titled “OnPoolChanged”public event PoolChangedArgs<T>? OnPoolChangedEvent Type
Section titled “Event Type”OnCreateObject
Section titled “OnCreateObject”Called when an object is created.
[Obsolete("Use 'OnPoolChanged' instead. This will be removed in build.", true)]public event Action<T>? OnCreateObjectEvent Type
Section titled “Event Type”OnDestroyObject
Section titled “OnDestroyObject”Called when an object is destroyed.
[Obsolete("Use 'OnPoolChanged' instead. This will be removed in build.", true)]public event Action<T>? OnDestroyObjectEvent Type
Section titled “Event Type”OnGetObject
Section titled “OnGetObject”Called when an object is retrieved.
[Obsolete("Use 'OnPoolChanged' instead. This will be removed in build.", true)]public event Action<T>? OnGetObjectEvent Type
Section titled “Event Type”OnReturnObject
Section titled “OnReturnObject”Called when an object is put back into the pool.
[Obsolete("Use 'OnPoolChanged' instead. This will be removed in build.", true)]public event Action<T>? OnReturnObject