Table of Contents

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.GetComponentInChildren<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: an ActivableEntityComponent whose Enabled is false is skipped unless includeDisabled is set. A component that cannot be disabled is always found.
  • Retrieving a single component or all components of a specified type.

Methods

GetComponentInChildrenAndSelf<T>(Entity, bool)

Performs a breadth-first search of the entity and its descendants for a component of the specified type.

public static T? GetComponentInChildrenAndSelf<T>(this Entity entity, bool includeDisabled = false) where T : EntityComponent

Parameters

entity Entity

The Entity to search within.

includeDisabled bool

Whether an ActivableEntityComponent with Enabled false counts.

Returns

T

The first component of type T found in the entity's descendants, or null if none exists.

Type Parameters

T

The type of component to retrieve.

Exceptions

ArgumentNullException

Thrown if the entity is null.

GetComponentInChildren<T>(Entity, bool)

Searches the entity's descendants breadth-first for the first component of the specified type.

public static T? GetComponentInChildren<T>(this Entity entity, bool includeDisabled = false) where T : EntityComponent

Parameters

entity Entity

The Entity to search within.

includeDisabled bool

Whether an ActivableEntityComponent with Enabled false counts.

Returns

T

The first component of type T found in the entity's descendants, or null if none exists.

Type Parameters

T

The type of component to retrieve.

Exceptions

ArgumentNullException

Thrown if the entity is null.

GetComponentInDescendantsAndSelf<T>(Entity, bool)

Performs a depth-first search of the entity and then its descendants for the first component of the specified type.

public static T? GetComponentInDescendantsAndSelf<T>(this Entity entity, bool includeDisabled = false) where T : EntityComponent

Parameters

entity Entity

The entity.

includeDisabled bool

Whether an ActivableEntityComponent with Enabled false counts.

Returns

T

The component on the entity itself when it has one, otherwise the first found walking down each child in turn, or null if none exists.

Type Parameters

T

The type of component.

Exceptions

ArgumentNullException

The entity was null.

GetComponentInParent<T>(Entity, bool)

Performs a search of the entity and its ancestors for a component of the specified type.

public static T? GetComponentInParent<T>(this Entity entity, bool includeDisabled = false) where T : EntityComponent

Parameters

entity Entity

The entity.

includeDisabled bool

Whether an ActivableEntityComponent with Enabled false counts.

Returns

T

The component, or null if none exists.

Type Parameters

T

The type of component.

Exceptions

ArgumentNullException

The entity was null.

GetComponentsInChildrenAndSelf<T>(Entity, bool)

Gets all components of the specified type on the entity and its direct children.

public static IEnumerable<T> GetComponentsInChildrenAndSelf<T>(this Entity entity, bool includeDisabled = false) where T : EntityComponent

Parameters

entity Entity

The entity.

includeDisabled bool

Whether an ActivableEntityComponent with Enabled false counts.

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)

Gets all components of the specified type on the entity's direct children.

public static IEnumerable<T> GetComponentsInChildren<T>(this Entity entity, bool includeDisabled = false) where T : EntityComponent

Parameters

entity Entity

The entity.

includeDisabled bool

Whether an ActivableEntityComponent with Enabled false counts.

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 its descendants for all components of the specified type.

public static IEnumerable<T> GetComponentsInDescendantsAndSelf<T>(this Entity entity, bool includeDisabled = false) where T : EntityComponent

Parameters

entity Entity

The entity.

includeDisabled bool

Whether an ActivableEntityComponent with Enabled false counts.

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's descendants for all components of the specified type.

public static IEnumerable<T> GetComponentsInDescendants<T>(this Entity entity, bool includeDisabled = false) where T : EntityComponent

Parameters

entity Entity

The entity.

includeDisabled bool

Whether an ActivableEntityComponent with Enabled false counts.

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 its ancestors for all components of the specified type.

public static IEnumerable<T> GetComponentsInParent<T>(this Entity entity, bool includeDisabled = false) where T : EntityComponent

Parameters

entity Entity

The entity.

includeDisabled bool

Whether an ActivableEntityComponent with Enabled false counts.

Returns

IEnumerable<T>

An iteration on the components.

Type Parameters

T

The type of component.

Exceptions

ArgumentNullException

The entity was null.