Table of Contents

Entity Extensions

Extension methods for Entity, in the Stride.CommunityToolkit.Engine namespace. They cover the four things you end up doing to an entity constantly: getting components off it, finding it again, attaching a controller, and drawing a gizmo on it.

Components

var (model, light) = entity.Get<ModelComponent, LightComponent>();

Finding entities

  • FindEntity() - Finds a direct child by name.
  • FindEntityRecursive() - Searches the whole subtree, not only the immediate children.
  • WorldPosition() - The entity's position in world space rather than relative to its parent, updating the transform hierarchy first unless you ask it not to.
  • Remove() - Takes the entity out of its scene by setting Scene to null.

To search a whole scene rather than one entity's subtree:

  • scene.GetComponentsInScene<T>() - Every component of type T on any entity of the scene, its children and, unless includeChildScenes is false, its child scenes. GetComponentInScene<T>() is the first one or null.
  • game.GetComponentsInScene<T>() - The same across every scene the game has loaded. Both walk every entity, so use them for a lookup at start or on an event, not every frame; a manager that many scripts need is better registered as a service, see the FAQ.

Turning and moving

Extension methods for TransformComponent, in the same namespace:

  • Translate() and Rotate() - Move or turn by an amount in the entity's own space (Space.Self, the default) or in world space.
  • LookAt() - Turns the entity's forward axis (-Z) towards a world point, with an optional smooth fraction for a turn that eases over several frames.
  • FaceDirection() - LookAt along a direction instead of towards a point: a character facing the way it moves, a projectile facing its velocity. A zero direction is ignored.
  • RotateAround() - Swings the entity about an axis through a point and turns it by the same angle, a moon keeping one face to its planet. Point and axis are in the parent's space, which is world space for a root entity; call it every frame with speed * deltaTime for an orbit.

Camera controllers

These are the entity-level counterparts of the Game extensions; use them when you already hold the camera entity.

See Camera Controllers for the keys, the on-screen help and every option on both scripts.

Gizmos

  • AddGizmo() - Draws a translation gizmo at the entity, with optional per-axis colours and axis letters.
  • AddLightDirectionalGizmo() - Draws which way a directional light is pointing, which is otherwise invisible.