Method AddComponent
AddComponent(Entity, ComponentType)
Adds a component to an entity.
Declaration
public void AddComponent(Entity entity, ComponentType componentType)
Parameters
Type | Name | Description |
---|---|---|
Entity | entity | The Entity. |
ComponentType | componentType | The type of component to add. |
Remarks
Can add any kind of component except chunk components. For chunk components, use AddChunkComponentData<T>(Entity).
Adding a component changes the entity's archetype and results in the entity being moved to a different chunk.
The added component has the default values for the type.
If the Entity object refers to an entity that already has the specified ComponentType, the function returns false without performing any modifications.
Important: This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before adding the component. No additional jobs can start before the method is finished. A sync point can cause a drop in performance because the ECS framework might not be able to use the processing power of all available cores.
Exceptions
Type | Condition |
---|---|
ArgumentException | The Entity does not exist. |