Version: Unity 7.0 Alpha (7000.0)
LanguageEnglish
  • C#

EntityCommandBuffer.AddComponent

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public void AddComponent(Entity e, T component);

Parameters

Parameter Description
e The entity to have the component added.
component The value to add on the new component in playback for the entity.

Description

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

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


Declaration

public void AddComponent(NativeArray<Entity> entities, T component);

Parameters

Parameter Description
entities The NativeArray of entities to have the component added.
component The value to add on the new component in playback for all entities in the NativeArray.

Description

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

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


Declaration

public void AddComponent(Entity e);

Parameters

Parameter Description
e The entity to have the component added.

Description

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

At playback, this command does nothing if the entity already has the component. Throws an error if this entity is destroyed before playback, if T is type Entity or Prefab, or adding this component type makes the archetype too large.


Declaration

public void AddComponent(NativeArray<Entity> entities);

Parameters

Parameter Description
entities The NativeArray of entities to have the component added.

Description

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

At playback, if an entity already has this component, it is skipped. Throws an error if any entity is destroyed before playback, if T is type Entity or Prefab, or adding this component type makes the archetype too large.


Declaration

public void AddComponent(Entity e, ComponentType componentType);

Parameters

Parameter Description
e The entity to get the additional component.
componentType The type of component to add.

Description

Records a command to add a component to an entity.

At playback, this command does nothing if the entity already has the component. Throws an error if any entity is destroyed before playback, if component is type Entity or Prefab, or adding this component type makes the archetype too large.


Declaration

public void AddComponent(NativeArray<Entity> entities, ComponentType componentType);

Parameters

Parameter Description
entities The NativeArray of entities to have the component added.
componentType The type of component to add.

Description

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

At playback, if an entity already has this component, it is skipped. Throws an error if any entity is destroyed before playback, if component is type Entity or Prefab, or adding this component type makes the archetype too large.


Declaration

public void AddComponent(Entity e, ref ComponentTypeSet componentTypeSet);

Parameters

Parameter Description
e The entity to get additional components.
componentTypeSet The types of components to add.

Description

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

At playback, you can include a component type that the entity already has. Throws 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.


Declaration

public void AddComponent(NativeArray<Entity> entities, ref ComponentTypeSet componentTypeSet);

Parameters

Parameter Description
entities The NativeArray of entities to have the components added.
componentTypeSet The types of components to add.

Description

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

At playback, you can include a component type that any of the entities already have. Throws 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.


Declaration

public void AddComponent(EntityQuery entityQuery, ComponentType componentType, EntityQueryCaptureMode queryCaptureMode);

Parameters

Parameter Description
entityQuery The query specifying the entities to which the component is added.
componentType The type of component to add.
queryCaptureMode Controls when the entities matching entityQuery are computed and captured.

Description

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

Does not affect entities which already have the component.


Obsolete This method now takes an extra parameter to control when the query is evaluated. To preserve the current semantics, use EntityQueryCaptureMode.AtRecord (RemovedAfter Entities 2.0).

Declaration

public void AddComponent(EntityQuery entityQuery, ComponentType componentType);

Parameters

Parameter Description
entityQuery The query specifying the entities to which the component is added.
componentType The type of component to add.

Description

Obsolete. Use EntityCommandBuffer.AddComponent instead.


Declaration

public void AddComponent(EntityQuery entityQuery, EntityQueryCaptureMode queryCaptureMode);

Parameters

Parameter Description
entityQuery The query specifying the entities to which the component is added.
queryCaptureMode Controls when the entities matching entityQuery are computed and captured.

Description

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

Does not affect entities which already have the component.


Obsolete This method now takes an extra parameter to control when the query is evaluated. To preserve the current semantics, use EntityQueryCaptureMode.AtRecord (RemovedAfter Entities 2.0).

Declaration

public void AddComponent(EntityQuery entityQuery);

Parameters

Parameter Description
entityQuery The query specifying the entities to which the component is added.

Description

Obsolete. Use EntityCommandBuffer.AddComponent instead.


Declaration

public void AddComponent(EntityQuery entityQuery, T value);

Parameters

Parameter Description
entityQuery The query specifying the entities to which the component is added.
value The value to set on the new component in playback for all entities matching the query.

Description

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.

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.

At playback, this command throws an error if one of these entities is destroyed before playback. (With safety checks enabled, an exception is thrown. Without safety checks, playback will perform invalid and unsafe memory access.)


Declaration

public void AddComponent(EntityQuery entityQuery, ref ComponentTypeSet componentTypeSet, EntityQueryCaptureMode queryCaptureMode);

Parameters

Parameter Description
entityQuery The query specifying the entities to which the components are added.
componentTypeSet The types of components to add.
queryCaptureMode Controls when the entities matching entityQuery are computed and captured.

Description

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

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.

At playback, this command throws an error if one of these entities is destroyed before playback. (With safety checks enabled, an exception is thrown. Without safety checks, playback will perform invalid and unsafe memory access.)


Obsolete This method now takes an extra parameter to control when the query is evaluated. To preserve the current semantics, use EntityQueryCaptureMode.AtRecord (RemovedAfter Entities 2.0).

Declaration

public void AddComponent(EntityQuery entityQuery, ref ComponentTypeSet componentTypeSet);

Parameters

Parameter Description
entityQuery The query specifying the entities to which the component is added.
componentTypeSet The types of components to add.

Description

Obsolete. Use EntityCommandBuffer.AddComponent instead.