Table of Contents

Class EntityExtensions

Namespace
Stride.CommunityToolkit.Engine
Assembly
Stride.CommunityToolkit.dll

Provides extension methods for Entity to simplify common operations.

public static class EntityExtensions
Inheritance
EntityExtensions

Methods

Add2DCameraController(Entity)

public static void Add2DCameraController(this Entity entity)

Parameters

entity Entity

Add3DCameraController(Entity)

Adds an interactive camera script Basic3DCameraController to the specified entity, enabling camera movement and rotation through various input methods.

public static void Add3DCameraController(this Entity entity)

Parameters

entity Entity

The entity to which the interactive camera script will be added.

Remarks

The camera entity can be moved using W, A, S, D, Q and E, arrow keys, a gamepad's left stick or dragging/scaling using multi-touch. Rotation is achieved using the Numpad, the mouse while holding the right mouse button, a gamepad's right stick, or dragging using single-touch.

AddGizmo(Entity, GraphicsDevice, Color?, Color?, Color?, bool, bool)

Adds a TranslationGizmo to the specified entity with optional custom colors.

public static void AddGizmo(this Entity entity, GraphicsDevice graphicsDevice, Color? redColor = null, Color? greenColor = null, Color? blueColor = null, bool showAxisName = false, bool rotateAxisNames = true)

Parameters

entity Entity

The entity to which the gizmo will be added.

graphicsDevice GraphicsDevice

The graphics device used for rendering the gizmo.

redColor Color?

Optional custom color for the X-axis of the gizmo. If not specified, a default color is used.

greenColor Color?

Optional custom color for the Y-axis of the gizmo. If not specified, a default color is used.

blueColor Color?

Optional custom color for the Z-axis of the gizmo. If not specified, a default color is used.

showAxisName bool
rotateAxisNames bool

Examples

This example shows how to add a gizmo to an entity with the default colors:

var entity = new Entity();
// Assume 'game' is an existing Game instance
entity.AddGizmo(game.GraphicsDevice);

AddLightDirectionalGizmo(Entity, GraphicsDevice, Color?)

Adds a directional light gizmo to the specified entity for visual representation and manipulation in the editor or during runtime.

public static void AddLightDirectionalGizmo(this Entity entity, GraphicsDevice graphicsDevice, Color? color = null)

Parameters

entity Entity

The entity to which the directional light gizmo will be added.

graphicsDevice GraphicsDevice

The graphics device used to render the gizmo.

color Color?

Optional color for the gizmo. If not specified, a default color is used.

Examples

This example shows how to add a light directional gizmo to an entity with the default colors:

var entity = new Entity();
// Assume 'game' is an existing Game instance
entity.AddLightDirectionalGizmo(game.GraphicsDevice);

Remarks

This method is useful for visually representing the direction and orientation of a directional light in a scene. The gizmo can be used during runtime to provide a visual reference for the light's direction.

FindEntity(Entity, string)

Searches for an entity by name within the top-level entities of the current scene.

public static Entity? FindEntity(this Entity entity, string name)

Parameters

entity Entity

The reference entity used to access the scene.

name string

The name of the entity to find.

Returns

Entity

The first entity matching the specified name, or null if no match is found. This search does not include child entities.

FindEntityRecursive(Entity, string)

Searches for an entity by name within the top-level entities of the current scene.

public static Entity? FindEntityRecursive(this Entity parent, string name)

Parameters

parent Entity

The reference entity used to access the scene.

name string

The name of the entity to find.

Returns

Entity

The first entity matching the specified name, or null if no match is found. This search does not include child entities.

GetComponentInChildren<T>(Entity)

Recursively searches for the first component of the specified type in the entity's children.

public static T? GetComponentInChildren<T>(this Entity entity)

Parameters

entity Entity

Returns

T

Type Parameters

T

GetComponent<T>(Entity)

Retrieves the first component of the specified type from the entity.

public static T? GetComponent<T>(this Entity entity)

Parameters

entity Entity

Returns

T

The first component of the specified type, or null if no such component exists.

Type Parameters

T

The type of component to retrieve.

GetComponents<T>(Entity)

Retrieves all components of the specified type from the entity.

public static IEnumerable<T> GetComponents<T>(this Entity entity)

Parameters

entity Entity

Returns

IEnumerable<T>

An IEnumerable of components of the specified type.

Type Parameters

T

The type of components to retrieve.

Remove(Entity)

Removes the entity from its current scene by setting its Scene property to null.

public static void Remove(this Entity entity)

Parameters

entity Entity

The entity to be removed from its current scene.

TryGetComponent<T>(Entity, out T?)

Tries to retrieve a component of type T from the given entity.

public static bool TryGetComponent<T>(this Entity entity, out T? result)

Parameters

entity Entity

The entity from which to retrieve the component.

result T

When this method returns, contains the first component of type

Returns

bool

true if a component of type T is found in the entity; otherwise, false.

Type Parameters

T

The type of component to retrieve.

WorldPosition(Entity, bool)

An easier way to get the previous frames world position rather than getting TranslationVector from WorldMatrix

public static Vector3 WorldPosition(this Entity entity, bool updateTransforms = true)

Parameters

entity Entity

The Entity to get the World Position

updateTransforms bool

If true it will get the current frames world matrix

Returns

Vector3

The Vector3 as the World Position of the Entity