PoolableReference(T) Class

ClockStone Audio Toolkit

PoolableReferenceT Class

Auxiliary class to overcome the problem of references to pooled objects that should become null when objects are moved back to the pool after calling Destroy(GameObject).
Inheritance Hierarchy
SystemObject  (Default Namespace)PoolableReferenceT

Namespace:  (Default Namespace)
Assembly:  AudioToolkit (in AudioToolkit.dll) Version: 8.2.0.0 (8.2.0.0)
Syntax
C#
public class PoolableReference<T>
where T : Component

Type Parameters

T
A UnityEngine.Component

The PoolableReferenceT type exposes the following members.

Constructors
  NameDescription
Public methodPoolableReferenceT
Initializes a new instance of the PoolableReferenceT class with a null reference.
Public methodPoolableReferenceT(T)
Initializes a new instance of the PoolableReferenceT class with the specified reference.
Public methodPoolableReferenceT(PoolableReferenceT)
Initializes a new instance of the PoolableReferenceT class from a given PoolableReferenceT.
Top
Methods
  NameDescription
Public methodGet
Gets the reference to the script component, or null if the object was already destroyed or moved to the pool.
Public methodReset
Resets the reference to null.
Public methodSet(T)
Public methodSet(T, Boolean)
Sets the reference to a poolable object with the specified component.
Top
Examples
Instead of a normal reference to a script component on a poolable object use
MyScriptComponent scriptComponent = PoolableObjectController.Instantiate( prefab ).GetComponent<MyScriptComponent>();
var myReference = new PoolableReference<MyScriptComponent>( scriptComponent );
if( myReference.Get() != null ) // will check if poolable instance still belongs to the original object
{
    myReference.Get().MyComponentFunction();
}
See Also