Search Results for

    Show / Hide Table of Contents

    Class GameObjectExtensions

    UnityEngine.GameObject Based Extension Methods

    Inheritance
    System.Object
    GameObjectExtensions
    Namespace: GDX
    Syntax
    [VisualScriptingCompatible((short)2)]
    public static class GameObjectExtensions

    Methods

    | Improve this Doc View Source

    DestroyChildren(GameObject, Boolean, Boolean)

    Destroy child UnityEngine.GameObject.

    Declaration
    public static void DestroyChildren(this GameObject targetGameObject, bool deactivateBeforeDestroy = true, bool destroyInactive = true)
    Parameters
    Type Name Description
    UnityEngine.GameObject targetGameObject

    The parent UnityEngine.GameObject to look at.

    System.Boolean deactivateBeforeDestroy

    Should the targetGameObject's children be deactivated before destroying? This can be used to immediately hide an object, that will be destroyed at the end of the frame.

    System.Boolean destroyInactive

    Should inactive UnityEngine.GameObject be destroyed as well?

    Exceptions
    Type Condition
    UnsupportedRuntimeException

    Not supported on DOTS Runtime.

    | Improve this Doc View Source

    GetFirstComponentInChildrenComplex<T>(GameObject, Boolean, Boolean, Int32)

    A slightly more complex version of UnityEngine.Component.GetComponentInChildren<T>(System.Boolean) which allows for different hinted search options.

    Declaration
    public static T GetFirstComponentInChildrenComplex<T>(this GameObject targetGameObject, bool includeInactive = false, bool lookInChildrenFirst = false, int maxLevelsOfRecursion = -1)
        where T : Component
    Parameters
    Type Name Description
    UnityEngine.GameObject targetGameObject

    The target UnityEngine.GameObject to use as the base for the search.

    System.Boolean includeInactive

    Include inactive child UnityEngine.GameObjects when looking for the UnityEngine.Component.

    System.Boolean lookInChildrenFirst

    Should children UnityEngine.GameObject be searched before the targetGameObject's UnityEngine.GameObject.

    System.Int32 maxLevelsOfRecursion

    The maximum levels of recursion when looking for a UnityEngine.Component, -1 for infinite recursion.

    Returns
    Type Description
    T

    The first found UnityEngine.Component.

    Type Parameters
    Name Description
    T

    The target UnityEngine.Component type that is being looked for.

    Remarks

    If the maxLevelsOfRecursion is set to 1; this will search the targetGameObject and its immediate children only.

    The internal UnityEngine.Component.GetComponentInChildren<T>(System.Boolean) has optimizations internally in engine code which make it faster in different scenarios.

    Exceptions
    Type Condition
    UnsupportedRuntimeException

    Not supported on DOTS Runtime.

    | Improve this Doc View Source

    GetOrAddComponent<T>(GameObject)

    Get a component by type from a targetGameObject, if it is not found add and return it.

    Declaration
    public static T GetOrAddComponent<T>(this GameObject targetGameObject)
        where T : Component
    Parameters
    Type Name Description
    UnityEngine.GameObject targetGameObject

    The UnityEngine.GameObject that we should query for the component.

    Returns
    Type Description
    T

    The component on the targetGameObject.

    Type Parameters
    Name Description
    T

    The type of component.

    Remarks

    Adding a component at runtime is a performance nightmare. Use with caution!

    Exceptions
    Type Condition
    UnsupportedRuntimeException

    Not supported on DOTS Runtime.

    | Improve this Doc View Source

    GetScenePath(GameObject)

    Get an in scene path to the targetGameObject.

    Declaration
    public static string GetScenePath(this GameObject targetGameObject)
    Parameters
    Type Name Description
    UnityEngine.GameObject targetGameObject

    The UnityEngine.GameObject which to derive a path from.

    Returns
    Type Description
    System.String

    A created path System.String.

    Exceptions
    Type Condition
    UnsupportedRuntimeException

    Not supported on DOTS Runtime.

    • Improve this Doc
    • View Source
    In This Article
    Back to top Built on 2024-01-01 against 1f69a68.
    Generated by Dox+DocFX.