Class ObjectPool<T> | Core RP Library | 7.2.1
docs.unity3d.com
    Show / Hide Table of Contents

    Class ObjectPool<T>

    Generic object pool.

    Inheritance
    Object
    ObjectPool<T>
    Namespace: UnityEngine.Rendering
    Syntax
    public class ObjectPool<T>
        where T : new()
    Type Parameters
    Name Description
    T

    Type of the object pool.

    Constructors

    ObjectPool(UnityAction<T>, UnityAction<T>, Boolean)

    Constructor.

    Declaration
    public ObjectPool(UnityAction<T> actionOnGet, UnityAction<T> actionOnRelease, bool collectionCheck = true)
    Parameters
    Type Name Description
    UnityAction<T> actionOnGet

    Action on get.

    UnityAction<T> actionOnRelease

    Action on release.

    Boolean collectionCheck

    True if collection integrity should be checked.

    Properties

    countActive

    Number of active objects in the pool.

    Declaration
    public int countActive { get; }
    Property Value
    Type Description
    Int32

    countAll

    Number of objects in the pool.

    Declaration
    public int countAll { get; }
    Property Value
    Type Description
    Int32

    countInactive

    Number of inactive objects in the pool.

    Declaration
    public int countInactive { get; }
    Property Value
    Type Description
    Int32

    Methods

    Get()

    Get an object from the pool.

    Declaration
    public T Get()
    Returns
    Type Description
    T

    A new object from the pool.

    Get(out T)

    Get et new PooledObject.

    Declaration
    public ObjectPool<T>.PooledObject Get(out T v)
    Parameters
    Type Name Description
    T v

    Output new typed object.

    Returns
    Type Description
    ObjectPool.PooledObject<>

    New PooledObject

    Release(T)

    Release an object to the pool.

    Declaration
    public void Release(T element)
    Parameters
    Type Name Description
    T element

    Object to release.

    In This Article
    • Constructors
      • ObjectPool(UnityAction<T>, UnityAction<T>, Boolean)
    • Properties
      • countActive
      • countAll
      • countInactive
    • Methods
      • Get()
      • Get(out T)
      • Release(T)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023