docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method SetComponent

    SetComponent<T>(EntityCommandBuffer, Entity, T)

    Records a command to set a managed component for an entity.

    Declaration
    public static void SetComponent<T>(this EntityCommandBuffer ecb, Entity e, T component) where T : class, IComponentData, new()
    Parameters
    Type Name Description
    EntityCommandBuffer ecb

    This entity command buffer.

    Entity e

    The entity to set the component value on.

    T component

    The component value to add.

    Type Parameters
    Name Description
    T

    The type of component to set.

    Remarks

    At playback, this command throws an error if this entity is destroyed before playback, if this entity is still deferred, if the entity has the Prefab tag, or if the entity doesn't have the shared component type.

    Exceptions
    Type Condition
    NullReferenceException

    Throws if an Allocator was not passed in when the EntityCommandBuffer was created.

    InvalidOperationException

    Throws if this EntityCommandBuffer has already been played back.

    SetComponent<T>(EntityCommandBuffer, EntityQuery, T)

    Records a command to set a managed component value for all entities matching a query.

    Declaration
    public static void SetComponent<T>(this EntityCommandBuffer ecb, EntityQuery query, T component) where T : class, IComponentData, new()
    Parameters
    Type Name Description
    EntityCommandBuffer ecb

    This entity command buffer.

    EntityQuery query

    The query specifying which entities to set the component value for.

    T component

    The component value to set.

    Type Parameters
    Name Description
    T

    The type of component to set.

    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.

     If any entity does not have the component type at playback , playback Entities which already have the component type will have the component set to the value.
    
    Exceptions
    Type Condition
    InvalidOperationException

    Thrown in playback if one or more of the entities does not have the component type or has been destroyed. (With safety checks disabled, playback will perform invalid and unsafe memory access.).

    NullReferenceException

    Throws if an Allocator was not passed in when the EntityCommandBuffer was created.

    InvalidOperationException

    Throws if this EntityCommandBuffer has already been played back.

    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)