Class EntitySearchExtensions
- Namespace
- Stride.CommunityToolkit.Engine
- Assembly
- Stride.CommunityToolkit.dll
Provides extension methods for searching and retrieving EntityComponent instances within an Entity hierarchy. This class includes methods for performing breadth-first and depth-first searches to find components in children, descendants, and ancestors of an entity.
public static class EntitySearchExtensions
- Inheritance
-
EntitySearchExtensions
Examples
Example usage:
var component = entity.GetComponentInChildrenBFS<MyComponent>();
var allComponents = entity.GetComponentsInDescendants<MyComponent>();
Remarks
The methods in this class support various search options, including:
- Searching only in children or including the entity itself.
- Including or excluding disabled components.
- Retrieving a single component or all components of a specified type.
Methods
GetComponentInChildrenAndSelf<T>(Entity)
Performs a breadth first search of the entity and it's children for a component of the specified type.
public static T? GetComponentInChildrenAndSelf<T>(this Entity entity) where T : EntityComponent
Parameters
entity
EntityThe entity.
Returns
- T
The component or null if does no exist.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.
GetComponentInChildrenAndSelf<T>(Entity, bool)
Performs a breadth first search of the entity and it's children for a component of the specified type.
public static T? GetComponentInChildrenAndSelf<T>(this Entity entity, bool includeDisabled = false) where T : ActivableEntityComponent
Parameters
entity
EntityThe entity.
includeDisabled
boolShould search include ActivableEntityComponent where Enabled is
false
.
Returns
- T
The component or null if does no exist.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.
GetComponentInChildrenBFS<T>(Entity)
Searches the entity's children using a breadth-first search (BFS) to find the first component of the specified type.
public static T? GetComponentInChildrenBFS<T>(this Entity entity) where T : EntityComponent
Parameters
Returns
- T
The first component of type
T
found in the entity's children, ornull
if none exists.
Type Parameters
T
The type of component to retrieve.
Exceptions
- ArgumentNullException
Thrown if the
entity
isnull
.
GetComponentInChildren<T>(Entity, bool)
Performs a breadth first search of the entities children for a component of the specified type.
public static T? GetComponentInChildren<T>(this Entity entity, bool includeDisabled = false) where T : ActivableEntityComponent
Parameters
entity
EntityThe entity.
includeDisabled
boolShould search include ActivableEntityComponent where Enabled is
false
.
Returns
- T
The component or null if does no exist.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.
GetComponentInParent<T>(Entity)
Performs a search of the entity and it's ancestors for a component of the specified type.
public static T? GetComponentInParent<T>(this Entity entity) where T : EntityComponent
Parameters
entity
EntityThe entity.
Returns
- T
The component or
null
if does no exist.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.
GetComponentInParent<T>(Entity, bool)
Performs a search of the entity and it's ancestors for a component of the specified type.
public static T? GetComponentInParent<T>(this Entity entity, bool includeDisabled = false) where T : ActivableEntityComponent
Parameters
entity
EntityThe entity.
includeDisabled
boolShould search include ActivableEntityComponent where Enabled is
false
.
Returns
- T
The component or
null
if does no exist.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.
GetComponentsInChildrenAndSelf<T>(Entity)
Performs a depth first search of the entity and it's children for all components of the specified type.
public static IEnumerable<T> GetComponentsInChildrenAndSelf<T>(this Entity entity) where T : EntityComponent
Parameters
entity
EntityThe entity.
Returns
- IEnumerable<T>
An iteration on the components.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.
GetComponentsInChildrenAndSelf<T>(Entity, bool)
Performs a depth first search of the entity and it's children for all components of the specified type.
public static IEnumerable<T> GetComponentsInChildrenAndSelf<T>(this Entity entity, bool includeDisabled = false) where T : ActivableEntityComponent
Parameters
entity
EntityThe entity.
includeDisabled
boolShould search include ActivableEntityComponent where Enabled is
false
.
Returns
- IEnumerable<T>
An iteration on the components.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.
GetComponentsInChildren<T>(Entity)
Performs a depth first search of the entities children for all components of the specified type.
public static IEnumerable<T> GetComponentsInChildren<T>(this Entity entity) where T : EntityComponent
Parameters
entity
EntityThe entity.
Returns
- IEnumerable<T>
An iteration on the components.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.
GetComponentsInChildren<T>(Entity, bool)
Performs a depth first search of the entities children for all components of the specified type.
public static IEnumerable<T> GetComponentsInChildren<T>(this Entity entity, bool includeDisabled = false) where T : ActivableEntityComponent
Parameters
entity
EntityThe entity.
includeDisabled
boolShould search include ActivableEntityComponent where Enabled is
false
.
Returns
- IEnumerable<T>
An iteration on the components.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.
GetComponentsInDescendantsAndSelf<T>(Entity)
Performs a depth first search of the entity and it's decendants for all components of the specified type.
public static IEnumerable<T> GetComponentsInDescendantsAndSelf<T>(this Entity entity) where T : EntityComponent
Parameters
entity
EntityThe entity.
Returns
- IEnumerable<T>
An iteration on the components.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.
GetComponentsInDescendantsAndSelf<T>(Entity, bool)
Performs a depth first search of the entity and it's decendants for all components of the specified type.
public static IEnumerable<T> GetComponentsInDescendantsAndSelf<T>(this Entity entity, bool includeDisabled = false) where T : ActivableEntityComponent
Parameters
entity
EntityThe entity.
includeDisabled
boolShould search include ActivableEntityComponent where Enabled is
false
.
Returns
- IEnumerable<T>
An iteration on the components.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.
GetComponentsInDescendants<T>(Entity)
Performs a depth first search of the entities decendants for all components of the specified type.
public static IEnumerable<T> GetComponentsInDescendants<T>(this Entity entity) where T : EntityComponent
Parameters
entity
EntityThe entity.
Returns
- IEnumerable<T>
An iteration on the components.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.
GetComponentsInDescendants<T>(Entity, bool)
Performs a depth first search of the entity and it's decendants for all components of the specified type.
public static IEnumerable<T> GetComponentsInDescendants<T>(this Entity entity, bool includeDisabled = false) where T : ActivableEntityComponent
Parameters
entity
EntityThe entity.
includeDisabled
boolShould search include ActivableEntityComponent where Enabled is
false
.
Returns
- IEnumerable<T>
An iteration on the components.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.
GetComponentsInParent<T>(Entity)
Performs a search of the entity and it's ancestors for all components of the specified type.
public static IEnumerable<T> GetComponentsInParent<T>(this Entity entity) where T : EntityComponent
Parameters
entity
EntityThe entity.
Returns
- IEnumerable<T>
An iteration on the components.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.
GetComponentsInParent<T>(Entity, bool)
Performs a search of the entity and it's ancestors for all components of the specified type.
public static IEnumerable<T> GetComponentsInParent<T>(this Entity entity, bool includeDisabled = false) where T : ActivableEntityComponent
Parameters
entity
EntityThe entity.
includeDisabled
boolShould search include ActivableEntityComponent where Enabled is
false
.
Returns
- IEnumerable<T>
An iteration on the components.
Type Parameters
T
The type of component.
Exceptions
- ArgumentNullException
The entity was
null
.