Documentation

Unity Engine


Unity Engine


AddComponent

Records a command to add component of type T to an entity.
Read time 7 minutesLast updated 2 days ago

Definition

  • Type: Method
  • Namespace: Unity.Entities
  • Assembly: UnityEngine.EntitiesModule

AddComponent<T>(int, Entity, T)

Records a command to add component of type T to an entity.
public void AddComponent<T>(int sortKey, Entity e, T component) where T : unmanaged, IComponentData

Parameters

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 IJobChunk.Execute.

The entity to have the component added.

component

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

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 T is type Entity or Prefab, or adding this componentType makes the archetype too large.

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

Records a command to add component of type T to a NativeArray of entities.
public void AddComponent<T>(int sortKey, NativeArray<Entity> entities, T component) where T : unmanaged, IComponentData

Parameters

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 IJobChunk.Execute.

The NativeArray of entities to have the component added.

component

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

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 T is type Entity or Prefab, or adding this componentType makes the archetype too large.

AddComponent<T>(int, Entity)

Records a command to add component of type T to an entity.
public void AddComponent<T>(int sortKey, Entity e) where T : unmanaged, IComponentData

Parameters

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 IJobChunk.Execute.

The entity to have the component added.

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 T is type Entity or Prefab, or adding this componentType makes the archetype too large.

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

Records a command to add component of type T to a NativeArray of entities.
public void AddComponent<T>(int sortKey, NativeArray<Entity> entities) where T : unmanaged, IComponentData

Parameters

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 IJobChunk.Execute.

The NativeArray of entities to have the component added.

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 T is type Entity or Prefab, or adding this componentType makes the archetype too large.

AddComponent(int, Entity, ComponentType)

Records a command to add a component to an entity.
public void AddComponent(int sortKey, Entity e, ComponentType componentType)

Parameters

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 IJobChunk.Execute.

The entity to get the additional component.

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 component type is type Entity or Prefab, or adding this componentType makes the archetype too large.

AddComponent(int, NativeArray<Entity>, ComponentType)

Records a command to add a component to a NativeArray of entities.
public void AddComponent(int sortKey, NativeArray<Entity> entities, ComponentType componentType)

Parameters

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 IJobChunk.Execute.

The NativeArray of entities to have the component added.

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 component type is type Entity or Prefab, or adding this componentType makes the archetype too large.

AddComponent(int, Entity, ComponentTypeSet)

Records a command to add one or more components to an entity.
public void AddComponent(int sortKey, Entity e, in ComponentTypeSet typeSet)

Parameters

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 IJobChunk.Execute.

The entity to get additional components.

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 any component type is type Entity or Prefab, or adding a component type makes the archetype too large.

AddComponent(int, NativeArray<Entity>, ComponentTypeSet)

Records a command to add one or more components to a NativeArray of entities.
public void AddComponent(int sortKey, NativeArray<Entity> entities, in ComponentTypeSet typeSet)

Parameters

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 IJobChunk.Execute.

The NativeArray of entities to have the components added.

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 component type is type Entity or Prefab, or adding a component type makes the archetype too large.