docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method TryGetComponent

    TryGetComponent(Entity, out T, out bool)

    Retrieves the component associated with the specified Entity, if it exists. Then reports if the instance still refers to a valid entity and that it has a component of type T.

    Declaration
    public bool TryGetComponent(Entity entity, out T componentData, out bool entityExists)
    Parameters
    Type Name Description
    Entity entity

    The entity.

    T componentData

    The component of type T for the given entity, if it exists.

    bool entityExists

    Denotes whether the given entity exists. Use to differentiate an invalid entity from the entity not having the given buffer.

    Returns
    Type Description
    bool

    True if the entity has a component of type T, and false if it does not.

    TryGetComponent(Entity, out T)

    Retrieves the component associated with the specified Entity, if it exists. Then reports if the instance still refers to a valid entity and that it has a component of type T.

    Declaration
    public bool TryGetComponent(Entity entity, out T componentData)
    Parameters
    Type Name Description
    Entity entity

    The entity.

    T componentData

    The component of type T for the given entity, if it exists.

    Returns
    Type Description
    bool

    True if the entity has a component of type T, and false if it does not.

    In This Article
    • TryGetComponent(Entity, out T, out bool)
    • TryGetComponent(Entity, out T)
    Back to top
    Copyright © 2025 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)