Entity Class

Base class for entities in the ECS. Supports hybrid approach: can be used as a component container (data-oriented) or as a behavior host (object-oriented) by overriding lifecycle methods.

public class Entity

Inheritance System.Object → Entity

Properties
Children Gets the read-only collection of child entities. The wrapper is created once and cached; it reflects live changes to the child list.
Id Unique ID for this entity. Assigned atomically at creation. IDs start at 1; 0 is reserved as an invalid/null sentinel.
IsActive Indicates whether this entity is active in the world. Inactive entities are skipped by the ECS processing and excluded from queries. Set this to false to deactivate the entity without destroying it.
IsRoot Gets whether this entity is a root entity (has no parent).
Parent Gets the parent entity, or null if this is a root entity.
PoolsCleared True after OnDestroy() has removed this entity's components from all pools. Used by EntityWorld to skip the redundant safety-net cleanup pass.
Tags Gets the tags for this entity as a read-only set. Use Brine2D.ECS.Entity.AddTag(System.String), Brine2D.ECS.Entity.RemoveTag(System.String), and Brine2D.ECS.Entity.ClearTags to modify tags so that validation and logging are applied consistently.
World The entity world this entity belongs to, or null if not yet added to a world.
Methods
AddBehavior<T>() Adds a behavior to this entity with automatic dependency injection.
AddBehavior<T>(Action<T>) Creates, configures, and adds a behavior of the specified type.
AddChild(Entity) Adds a child entity to this entity.
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.
Destroy() Destroys this entity, removing it from the world.
DetachFromParent() Detaches this entity from its parent, making it a root entity.
FindDescendant(string) Finds the first descendant entity with the specified name.
GetAllBehaviors() Gets all behaviors attached to this entity.
GetBehavior<T>() Gets a behavior of the specified type attached to this entity.
GetComponentInChildren<T>() Gets a component on this entity or any of its children (depth-first recursive search).
GetComponentInParent<T>() Gets a component on this entity or any of its ancestors.
GetDepth() Gets the depth of this entity in the hierarchy (0 = root).
GetDescendants() Gets all descendant entities (children, grandchildren, etc.) via iterative depth-first traversal.
GetDescendantsWithTag(string) Gets all descendants with the specified tag.
GetRoot() Gets the root entity of this hierarchy.
HasBehavior(Type) Checks if this entity has a behavior of the specified type (non-generic version). Used internally by query infrastructure for dynamic type checking.
HasBehavior<T>() Checks if this entity has a behavior of the specified type.
HasComponent(Type) Checks if this entity has a component of the specified type (non-generic version). Used internally by EntityQuery for dynamic type checking.
NotifyComponentEnabledChanged() Forwards IsEnabled change notifications to the world so cached queries built with OnlyEnabled() are invalidated.
OnDestroy() Called once when the entity is destroyed and removed from the world. Override to implement custom cleanup logic.
OnInitialize() Called once when the entity is created and added to the world. Override to implement initialization logic.
RemoveBehavior<T>() Removes a behavior from this entity.
RemoveChild(Entity) Removes a child entity from this entity (makes it a root entity). Delegates to SetParent(Entity) so any future side effects added there (events, transform propagation, etc.) apply through this path too.
SetActiveWithoutNotification(bool) Sets IsActive without notifying the world. Used during entity destruction to avoid O(n × q) redundant query invalidations that will be superseded by pool removal.
SetLogger(ILogger<Entity>) Sets the logger for this entity. Internal — called by CreateEntity<T>(string) after construction when the new() constraint prevents constructor injection.
SetParent(Entity) Sets the parent of this entity.
SetWorld(EntityWorld) Sets the world this entity belongs to. Internal - only called by EntityWorld and SceneManager.