docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method AddComponent

    AddComponent<T>(int, Entity, T)

    Records a command to add component of type T to an entity.

    Declaration
    public void AddComponent<T>(int sortKey, Entity e, T component) where T : unmanaged, IComponentData
    Parameters
    Type Name Description
    int sortKey

    A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The ChunkIndexInQuery provided by IJobEntity is an appropriate value to use for this parameter. In an IJobChunk pass the 'unfilteredChunkIndex' value from Execute(in ArchetypeChunk, int, bool, in v128).

    Entity e

    The entity to have the component added.

    T component

    The value to add on the new component in playback for the entity.

    Type Parameters
    Name Description
    T

    The type of component to add.

    Remarks

    At playback, if the entity already has this type of component, the value will just be set. Will throw an error if this entity is destroyed before playback, if this entity is still deferred, if T is type Entity or Prefab, or adding this componentType makes the archetype too large.

    Exceptions
    Type Condition
    NullReferenceException

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

    AddComponent<T>(int, NativeArray<Entity>, T)

    Records a command to add component of type T to a NativeArray of entities.

    Declaration
    public void AddComponent<T>(int sortKey, NativeArray<Entity> entities, T component) where T : unmanaged, IComponentData
    Parameters
    Type Name Description
    int sortKey

    A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The ChunkIndexInQuery provided by IJobEntity is an appropriate value to use for this parameter. In an IJobChunk pass the 'unfilteredChunkIndex' value from Execute(in ArchetypeChunk, int, bool, in v128).

    NativeArray<Entity> entities

    The NativeArray of entities to have the component added.

    T component

    The value to add on the new component in playback for all entities in the NativeArray.

    Type Parameters
    Name Description
    T

    The type of component to add.

    Remarks

    At playback, if any entity already has this type of component, the value will just be set. Will throw an error if any entity is destroyed before playback, if any entity is still deferred, if T is type Entity or Prefab, or adding this componentType makes the archetype too large.

    Exceptions
    Type Condition
    NullReferenceException

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

    AddComponent<T>(int, Entity)

    Records a command to add component of type T to an entity.

    Declaration
    public void AddComponent<T>(int sortKey, Entity e) where T : unmanaged, IComponentData
    Parameters
    Type Name Description
    int sortKey

    A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The ChunkIndexInQuery provided by IJobEntity is an appropriate value to use for this parameter. In an IJobChunk pass the 'unfilteredChunkIndex' value from Execute(in ArchetypeChunk, int, bool, in v128).

    Entity e

    The entity to have the component added.

    Type Parameters
    Name Description
    T

    The type of component to add.

    Remarks

    At playback, this command will do nothing if the entity already has the component. Will throw an error if this entity is destroyed before playback, if this entity is still deferred, if T is type Entity or Prefab, or adding this componentType makes the archetype too large.

    Exceptions
    Type Condition
    NullReferenceException

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

    AddComponent<T>(int, NativeArray<Entity>)

    Records a command to add component of type T to a NativeArray of entities.

    Declaration
    public void AddComponent<T>(int sortKey, NativeArray<Entity> entities) where T : unmanaged, IComponentData
    Parameters
    Type Name Description
    int sortKey

    A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The ChunkIndexInQuery provided by IJobEntity is an appropriate value to use for this parameter. In an IJobChunk pass the 'unfilteredChunkIndex' value from Execute(in ArchetypeChunk, int, bool, in v128).

    NativeArray<Entity> entities

    The NativeArray of entities to have the component added.

    Type Parameters
    Name Description
    T

    The type of component to add.

    Remarks

    At playback, if an entity already has this component, it will be skipped. Will throw an error if any entity is destroyed before playback, if any entity is still deferred, if T is type Entity or Prefab, or adding this componentType makes the archetype too large.

    Exceptions
    Type Condition
    NullReferenceException

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

    AddComponent(int, Entity, ComponentType)

    Records a command to add a component to an entity.

    Declaration
    public void AddComponent(int sortKey, Entity e, ComponentType componentType)
    Parameters
    Type Name Description
    int sortKey

    A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The ChunkIndexInQuery provided by IJobEntity is an appropriate value to use for this parameter. In an IJobChunk pass the 'unfilteredChunkIndex' value from Execute(in ArchetypeChunk, int, bool, in v128).

    Entity e

    The entity to get the additional component.

    ComponentType componentType

    The type of component to add.

    Remarks

    At playback, this command will do nothing if the entity already has the component. Will throw an error if this entity is destroyed before playback, if this entity is still deferred, if component type is type Entity or Prefab, or adding this componentType makes the archetype too large.

    Exceptions
    Type Condition
    NullReferenceException

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

    AddComponent(int, NativeArray<Entity>, ComponentType)

    Records a command to add a component to a NativeArray of entities.

    Declaration
    public void AddComponent(int sortKey, NativeArray<Entity> entities, ComponentType componentType)
    Parameters
    Type Name Description
    int sortKey

    A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The ChunkIndexInQuery provided by IJobEntity is an appropriate value to use for this parameter. In an IJobChunk pass the 'unfilteredChunkIndex' value from Execute(in ArchetypeChunk, int, bool, in v128).

    NativeArray<Entity> entities

    The NativeArray of entities to have the component added.

    ComponentType componentType

    The type of component to add.

    Remarks

    At playback, if an entity already has this component, it will be skipped. Will throw an error if any entity is destroyed before playback, if any entity is still deferred, if component type is type Entity or Prefab, or adding this componentType makes the archetype too large.

    Exceptions
    Type Condition
    NullReferenceException

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

    AddComponent(int, Entity, in ComponentTypeSet)

    Records a command to add one or more components to an entity.

    Declaration
    public void AddComponent(int sortKey, Entity e, in ComponentTypeSet typeSet)
    Parameters
    Type Name Description
    int sortKey

    A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The ChunkIndexInQuery provided by IJobEntity is an appropriate value to use for this parameter. In an IJobChunk pass the 'unfilteredChunkIndex' value from Execute(in ArchetypeChunk, int, bool, in v128).

    Entity e

    The entity to get additional components.

    ComponentTypeSet typeSet

    The types of components to add.

    Remarks

    At playback, it's not an error to include a component type that the entity already has. Will throw an error if this entity is destroyed before playback, if this entity is still deferred, if any component type is type Entity or Prefab, or adding a component type makes the archetype too large.

    Exceptions
    Type Condition
    NullReferenceException

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

    AddComponent(int, NativeArray<Entity>, in ComponentTypeSet)

    Records a command to add one or more components to a NativeArray of entities.

    Declaration
    public void AddComponent(int sortKey, NativeArray<Entity> entities, in ComponentTypeSet typeSet)
    Parameters
    Type Name Description
    int sortKey

    A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The ChunkIndexInQuery provided by IJobEntity is an appropriate value to use for this parameter. In an IJobChunk pass the 'unfilteredChunkIndex' value from Execute(in ArchetypeChunk, int, bool, in v128).

    NativeArray<Entity> entities

    The NativeArray of entities to have the components added.

    ComponentTypeSet typeSet

    The types of components to add.

    Remarks

    At playback, it's not an error to include a component type that any of the entities already have. Will throw an error if any entity is destroyed before playback, if any entity is still deferred, if any component type is type Entity or Prefab, or adding a component type makes the archetype too large.

    Exceptions
    Type Condition
    NullReferenceException

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

    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)