docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method GetComponentInParent

    GetComponentInParent<T>()

    Retrieves the component of Type T in the GameObject or any of its parents

    Declaration
    public T GetComponentInParent<T>() where T : Component
    Returns
    Type Description
    T

    Returns a component if a component matching the type is found, null otherwise

    Type Parameters
    Name Description
    T

    The type of Component to retrieve

    Remarks

    This will take a dependency on the component

    GetComponentInParent<T>(Component)

    Retrieves the component of Type T in the GameObject or any of its parents

    Declaration
    public T GetComponentInParent<T>(Component component) where T : Component
    Parameters
    Type Name Description
    Component component

    The Object to get the component from

    Returns
    Type Description
    T

    The component if a component matching the type is found, null otherwise

    Type Parameters
    Name Description
    T

    The type of component to retrieve

    Remarks

    This will take a dependency on the component

    GetComponentInParent<T>(GameObject)

    Retrieves the component of Type T in the GameObject or any of its parents

    Declaration
    public T GetComponentInParent<T>(GameObject gameObject) where T : Component
    Parameters
    Type Name Description
    GameObject gameObject

    The GameObject to get the component from

    Returns
    Type Description
    T

    The component if a component matching the type is found, null otherwise

    Type Parameters
    Name Description
    T

    The type of component to retrieve

    Remarks

    This will take a dependency on the component

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)