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
GetComponent<T>()- The first component of typeT, ornull.GetComponents<T>()- Every component of typeTon the entity.TryGetComponent<T>()- TheTryform, for when a missing component is expected rather than a bug.GetComponentInDescendantsAndSelf<T>()- The entity first, then its descendants depth-first, which is where the component usually is on an imported model.GetComponentInChildren<T>()searches the descendants only, breadth-first.Get<T1, T2, …>()- Fetches several components in one pass and returns them as a tuple, so you can deconstruct them into named locals. Overloads exist for two through sixteen types.
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 settingScenetonull.
To search a whole scene rather than one entity's subtree:
scene.GetComponentsInScene<T>()- Every component of typeTon any entity of the scene, its children and, unlessincludeChildScenesisfalse, its child scenes.GetComponentInScene<T>()is the first one ornull.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()andRotate()- 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 optionalsmoothfraction for a turn that eases over several frames.FaceDirection()-LookAtalong 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 withspeed * deltaTimefor an orbit.
Camera controllers
These are the entity-level counterparts of the Game extensions; use them when you already hold the camera entity.
Add2DCameraController()- Attaches the interactive 2D camera script, giving pan and zoom.Add3DCameraController()- Attaches the interactive 3D camera script, giving free-look movement and an on-screen key reminder.
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.