docs.unity3d.com
    Show / Hide Table of Contents

    Method AddComponentForEntityQuery

    AddComponentForEntityQuery(EntityQuery, ComponentType)

    Records a command to add a component to all entities matching a query.

    Declaration
    public void AddComponentForEntityQuery(EntityQuery entityQuery, ComponentType componentType)
    Parameters
    Type Name Description
    EntityQuery entityQuery

    The query specifying the entities to which the component is added.

    ComponentType componentType

    The type of component to add.

    Remarks

    The set of entities matching the query is 'captured' in the method call, and the recorded command stores an array of all these entities.

    Does not affect entities which already have the component.

    If one of these entities is destroyed before playback, playback will fail. (With safety checks enabled, an exception is thrown. Without safety checks, playback will perform invalid and unsafe memory access.)

    AddComponentForEntityQuery<T>(EntityQuery)

    Records a command to add a component to all entities matching a query.

    Declaration
    public void AddComponentForEntityQuery<T>(EntityQuery entityQuery)
    Parameters
    Type Name Description
    EntityQuery entityQuery

    The query specifying the entities to which the component is added.

    Type Parameters
    Name Description
    T

    The type of component to add.

    Remarks

    The set of entities matching the query is 'captured' in the method call, and the recorded command stores an array of all these entities.

    Does not affect entities which already have the component.

    If one of these entities is destroyed before playback, playback will fail. (With safety checks enabled, an exception is thrown. Without safety checks, playback will perform invalid and unsafe memory access.)

    AddComponentForEntityQuery<T>(EntityQuery, T)

    Records a command to add a component to all entities matching a query. Also sets the value of this new component on all the matching entities.

    Declaration
    public void AddComponentForEntityQuery<T>(EntityQuery entityQuery, T value)
        where T : struct, IComponentData
    Parameters
    Type Name Description
    EntityQuery entityQuery

    The query specifying the entities to which the component is added.

    T value

    The value to set on the new component in playback for all entities matching the query.

    Type Parameters
    Name Description
    T

    The type of component to add.

    Remarks

    The set of entities matching the query is 'captured' in the method call, and the recorded command stores an array of all these entities.

    Entities which already have the component type will have the component set to the value.

    If one of these entities is destroyed before playback, playback will fail. (With safety checks enabled, an exception is thrown. Without safety checks, playback will perform invalid and unsafe memory access.)

    AddComponentForEntityQuery(EntityQuery, ComponentTypes)

    Records a command to add multiple components to all entities matching a query.

    Declaration
    public void AddComponentForEntityQuery(EntityQuery entityQuery, ComponentTypes componentTypes)
    Parameters
    Type Name Description
    EntityQuery entityQuery

    The query specifying the entities to which the components are added.

    ComponentTypes componentTypes

    The types of components to add.

    Remarks

    The set of entities matching the query is 'captured' in the method call, and the recorded command stores an array of all these entities.

    Some matching entities may already have some or all of the specified components. After this operation, all matching entities will have all of the components.

    If one of these entities is destroyed before playback, playback will fail. (With safety checks enabled, an exception is thrown. Without safety checks, playback will perform invalid and unsafe memory access.)

    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