Interface IHierarchyCapability
- Namespace
- KeenEyes.Capabilities
- Assembly
- KeenEyes.Abstractions.dll
Capability interface for entity hierarchy operations.
public interface IHierarchyCapability
Examples
public void Install(IPluginContext context)
{
if (context.TryGetCapability<IHierarchyCapability>(out var hierarchy))
{
var children = hierarchy.GetChildren(parentEntity);
foreach (var child in children)
{
// Process child entities
}
}
}
Remarks
This capability provides access to parent-child relationship management for entities. Plugins and systems that need to traverse or manipulate entity hierarchies should request this capability via GetCapability<T>() rather than casting to the concrete World type.
Common use cases include UI systems that need to render children, transform propagation systems, and scene graph traversal.
Methods
AddChild(Entity, Entity)
Adds a child entity to a parent entity.
void AddChild(Entity parent, Entity child)
Parameters
Exceptions
- InvalidOperationException
Thrown when either entity is not alive, or when the relationship would create a circular hierarchy.
DespawnRecursive(Entity)
Destroys an entity and all its descendants recursively.
int DespawnRecursive(Entity entity)
Parameters
entityEntityThe entity to destroy along with all its descendants.
Returns
- int
The number of entities destroyed.
GetAncestors(Entity)
Gets all ancestors of an entity (parent, grandparent, etc.).
IEnumerable<Entity> GetAncestors(Entity entity)
Parameters
entityEntityThe entity to get ancestors for.
Returns
- IEnumerable<Entity>
An enumerable of all ancestor entities, starting with the immediate parent.
GetChildren(Entity)
Gets all immediate children of an entity.
IEnumerable<Entity> GetChildren(Entity entity)
Parameters
entityEntityThe entity to get children for.
Returns
- IEnumerable<Entity>
An enumerable of child entities.
GetDescendants(Entity)
Gets all descendants of an entity (children, grandchildren, etc.).
IEnumerable<Entity> GetDescendants(Entity entity)
Parameters
entityEntityThe entity to get descendants for.
Returns
- IEnumerable<Entity>
An enumerable of all descendant entities in breadth-first order.
GetParent(Entity)
Gets the parent of an entity.
Entity GetParent(Entity entity)
Parameters
entityEntityThe entity to get the parent for.
Returns
GetRoot(Entity)
Gets the root entity of the hierarchy containing the given entity.
Entity GetRoot(Entity entity)
Parameters
entityEntityThe entity to find the root for.
Returns
- Entity
The root entity (topmost ancestor with no parent). If the entity itself has no parent, returns the entity itself.
RemoveChild(Entity, Entity)
Removes a specific child from a parent entity.
bool RemoveChild(Entity parent, Entity child)
Parameters
Returns
- bool
True if the child was removed; false otherwise.
SetParent(Entity, Entity)
Sets the parent of an entity, establishing a parent-child relationship.
void SetParent(Entity child, Entity parent)
Parameters
childEntityThe entity to become a child.
parentEntityThe entity to become the parent. Pass Null to remove the parent.
Exceptions
- InvalidOperationException
Thrown when the child entity is not alive, or when setting the parent would create a circular relationship.