Method AddComponent
AddComponent<T>(Entity, T)
Records a command to add component of type T to an entity.
Declaration
public void AddComponent<T>(Entity e, T component) where T : unmanaged, IComponentData
Parameters
Type | Name | Description |
---|---|---|
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. Throws 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 component type makes the archetype too large.
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. |
AddComponent<T>(NativeArray<Entity>, T)
Records a command to add component of type T to a NativeArray of entities.
Declaration
public void AddComponent<T>(NativeArray<Entity> entities, T component) where T : unmanaged, IComponentData
Parameters
Type | Name | Description |
---|---|---|
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. Throws 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 component type makes the archetype too large.
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. |
AddComponent<T>(Entity)
Records a command to add component of type T to an entity.
Declaration
public void AddComponent<T>(Entity e) where T : unmanaged, IComponentData
Parameters
Type | Name | Description |
---|---|---|
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 does nothing if the entity already has the component. Throws 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 component type makes the archetype too large.
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. |
AddComponent<T>(NativeArray<Entity>)
Records a command to add component of type T to a NativeArray of entities.
Declaration
public void AddComponent<T>(NativeArray<Entity> entities) where T : unmanaged, IComponentData
Parameters
Type | Name | Description |
---|---|---|
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 is skipped. Throws an error if any entity is destroyed before playback, or if any entity is still deferred, if T is type Entity or Prefab, or adding this component type makes the archetype too large.
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. |
AddComponent(Entity, ComponentType)
Records a command to add a component to an entity.
Declaration
public void AddComponent(Entity e, ComponentType componentType)
Parameters
Type | Name | Description |
---|---|---|
Entity | e | The entity to get the additional component. |
ComponentType | componentType | The type of component to add. |
Remarks
At playback, this command does nothing if the entity already has the component. Throws an error if any entity is destroyed before playback, or if any entity is still deferred, if component is type Entity or Prefab, or adding this component type makes the archetype too large.
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. |
AddComponent(NativeArray<Entity>, ComponentType)
Records a command to add a component to a NativeArray of entities.
Declaration
public void AddComponent(NativeArray<Entity> entities, ComponentType componentType)
Parameters
Type | Name | Description |
---|---|---|
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 is skipped. Throws an error if any entity is destroyed before playback, or if any entity is still deferred, if component is type Entity or Prefab, or adding this component type makes the archetype too large.
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. |
AddComponent(Entity, in ComponentTypeSet)
Records a command to add one or more components to an entity.
Declaration
public void AddComponent(Entity e, in ComponentTypeSet componentTypeSet)
Parameters
Type | Name | Description |
---|---|---|
Entity | e | The entity to get additional components. |
ComponentTypeSet | componentTypeSet | The types of components to add. |
Remarks
At playback, you can include a component type that the entity already has. Throws 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. |
InvalidOperationException | Throws if this EntityCommandBuffer has already been played back. |
AddComponent(NativeArray<Entity>, in ComponentTypeSet)
Records a command to add one or more components to a NativeArray of entities.
Declaration
public void AddComponent(NativeArray<Entity> entities, in ComponentTypeSet componentTypeSet)
Parameters
Type | Name | Description |
---|---|---|
NativeArray<Entity> | entities | The NativeArray of entities to have the components added. |
ComponentTypeSet | componentTypeSet | The types of components to add. |
Remarks
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 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. |
InvalidOperationException | Throws if this EntityCommandBuffer has already been played back. |
AddComponent(EntityQuery, ComponentType, EntityQueryCaptureMode)
Records a command to add a component to all entities matching a query.
Declaration
public void AddComponent(EntityQuery entityQuery, ComponentType componentType, EntityQueryCaptureMode queryCaptureMode)
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. |
EntityQueryCaptureMode | queryCaptureMode | Controls when the entities matching |
Remarks
Does not affect entities which already have the component.
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. |
AddComponent(EntityQuery, ComponentType)
Obsolete. Use AddComponent(EntityQuery, ComponentType, EntityQueryCaptureMode) instead.
Declaration
[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)")]
public void AddComponent(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. |
AddComponent<T>(EntityQuery, EntityQueryCaptureMode)
Records a command to add a component to all entities matching a query.
Declaration
public void AddComponent<T>(EntityQuery entityQuery, EntityQueryCaptureMode queryCaptureMode)
Parameters
Type | Name | Description |
---|---|---|
EntityQuery | entityQuery | The query specifying the entities to which the component is added. |
EntityQueryCaptureMode | queryCaptureMode | Controls when the entities matching |
Type Parameters
Name | Description |
---|---|
T | The type of component to add. |
Remarks
Does not affect entities which already have the component.
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. |
AddComponent<T>(EntityQuery)
Obsolete. Use AddComponent<T>(EntityQuery, EntityQueryCaptureMode) instead.
Declaration
[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)")]
public void AddComponent<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. |
AddComponent<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 AddComponent<T>(EntityQuery entityQuery, T value) where T : unmanaged, 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.
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.)
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. |
AddComponent(EntityQuery, in ComponentTypeSet, EntityQueryCaptureMode)
Records a command to add multiple components to all entities matching a query.
Declaration
public void AddComponent(EntityQuery entityQuery, in ComponentTypeSet componentTypeSet, EntityQueryCaptureMode queryCaptureMode)
Parameters
Type | Name | Description |
---|---|---|
EntityQuery | entityQuery | The query specifying the entities to which the components are added. |
ComponentTypeSet | componentTypeSet | The types of components to add. |
EntityQueryCaptureMode | queryCaptureMode | Controls when the entities matching |
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.
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.)
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. |
AddComponent(EntityQuery, in ComponentTypeSet)
Obsolete. Use AddComponent(EntityQuery,ComponentTypeSet,EntityQueryCaptureMode) instead.
Declaration
[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)")]
public void AddComponent(EntityQuery entityQuery, in ComponentTypeSet componentTypeSet)
Parameters
Type | Name | Description |
---|---|---|
EntityQuery | entityQuery | The query specifying the entities to which the component is added. |
ComponentTypeSet | componentTypeSet | The types of components to add. |