docs.unity3d.com
    Show / Hide Table of Contents

    Class GameObjectOneWayCache

    Facilitates object pooling for a pre-specified collection of prefabs with the caveat that objects can be fetched from the cache but not returned. Every frame, the cache needs to be reset, which will return all objects to the pool

    Inheritance
    Object
    GameObjectOneWayCache
    Namespace: UnityEngine.Perception.Randomization.Randomizers.Utilities
    Syntax
    public class GameObjectOneWayCache : object

    Constructors

    GameObjectOneWayCache(Transform, GameObject[])

    Creates a new GameObjectOneWayCache

    Declaration
    public GameObjectOneWayCache(Transform parent, GameObject[] gameObjects)
    Parameters
    Type Name Description
    Transform parent

    The parent object all cached instances will be parented under

    GameObject[] gameObjects

    The gameObjects to cache

    Properties

    NumObjectsActive

    The number of active cache objects in the scene

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

    Methods

    GetOrInstantiate(GameObject)

    Retrieves an existing instance of the given gameObject from the cache if available. Otherwise, instantiate a new instance of the given gameObject.

    Declaration
    public GameObject GetOrInstantiate(GameObject gameObject)
    Parameters
    Type Name Description
    GameObject gameObject
    Returns
    Type Description
    GameObject

    GetOrInstantiate(Int32)

    Retrieves an existing instance of the given gameObject from the cache if available. Otherwise, instantiate a new instance of the given gameObject.

    Declaration
    public GameObject GetOrInstantiate(int index)
    Parameters
    Type Name Description
    Int32 index

    The index of the gameObject to instantiate

    Returns
    Type Description
    GameObject

    GetOrInstantiateRandomCachedObject()

    Retrieves an existing instance of a random gameObject from the cache if available. Otherwise, instantiate a new instance of the random gameObject.

    Declaration
    public GameObject GetOrInstantiateRandomCachedObject()
    Returns
    Type Description
    GameObject

    A random cached GameObject

    ResetAllObjects()

    Return all active cache objects back to an inactive state

    Declaration
    public void ResetAllObjects()

    ResetObject(GameObject)

    Returns the given cache object back to an inactive state

    Declaration
    public void ResetObject(GameObject gameObject)
    Parameters
    Type Name Description
    GameObject gameObject

    The object to make inactive

    Back to top
    Terms of use
    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