Entity.AddComponent Method
Definition¶
Namespace: Brine2D.ECS
| Overloads | |
|---|---|
| AddComponent<T>() | Creates and adds a component of the specified type. |
| AddComponent<T>(Action<T>) | Creates and adds a component with inline configuration. If the entity already has this component type, the configure action is applied to the existing one. |
| AddComponent<T>(T) | Adds an existing component instance to this entity. |
Entity.AddComponent\<T>() Method¶
Creates and adds a component of the specified type.
public Brine2D.ECS.Entity AddComponent<T>()
where T : Brine2D.ECS.Component, new();
Type parameters¶
T
Returns¶
Entity.AddComponent\<T>(Action\<T>) Method¶
Creates and adds a component with inline configuration. If the entity already has this component type, the configure action is applied to the existing one.
public Brine2D.ECS.Entity AddComponent<T>(System.Action<T>? configure)
where T : Brine2D.ECS.Component, new();
Type parameters¶
T
Parameters¶
configure System.Action<T>
Returns¶
Remarks¶
For new components, configure runs before the component is attached. Entity is null during configuration and OnAdded() has not yet been called. For duplicate components, configure is applied to the existing instance which is already attached.
Entity.AddComponent\<T>(T) Method¶
Adds an existing component instance to this entity.
public Brine2D.ECS.Entity AddComponent<T>(T component)
where T : Brine2D.ECS.Component;
Type parameters¶
T
Parameters¶
component T
Returns¶
Exceptions¶
System.InvalidOperationException
Thrown when the entity has been destroyed or is not attached to a world.
System.ArgumentException
Thrown when the runtime type of component does not match T,
which would cause the component to be stored under the wrong pool key.