stride3d/stride · error · ArgumentException
Entity shouldn't have a parent.
Error message
Entity shouldn't have a parent.
What it means
EntityManager.Add registers an entity as a root entity in the manager. It throws ArgumentException when the entity's Transform has a Parent, because entities with a parent are not roots — they belong to the hierarchy under their parent, not directly to the manager's root set.
Solutions
- Only add root entities (Transform.Parent == null) to the manager
- To relocate an entity, remove it from its current parent first (entity.Transform.Parent = null) or reparent via Transform.Parent
- Check entity.Transform?.Parent before calling Add
Example fix
// before
entityManager.Add(childEntity);
// after
if (childEntity.Transform?.Parent == null)
entityManager.Add(childEntity);
else
childEntity.Transform.Parent = null; // detach first if relocation is intended Defensive patterns
Strategy: validation
Validate before calling
if (entity.Transform?.Parent != null) return; // not a root, skip Add entityManager.Add(entity);
Type guard
static bool IsRootEntity(Stride.Engine.Entity e) => e?.Transform?.Parent == null;
Try / catch
try { entityManager.Add(entity); }
catch (ArgumentException ex) when (ex.Message.Contains("shouldn't have a parent")) { /* reparent or skip */ } Prevention
- Only add root entities to the manager; children live under their parent
- Reparent via Transform.Parent instead of manager Add/Remove
- Check Parent before hierarchy-manipulating calls
When it happens
Trigger: Calling entityManager.Add(entity) where entity.Transform.Parent != null, i.e. the entity was already added as a child of another entity.
Common situations: Re-adding an entity that is a child in a scene hierarchy; moving code that assumed flat entity lists into a parented scene; scripts adding child entities to the manager directly.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- parent cannot be null
- is not contained in a hierarchy.
- The control corresponding to the given parentId is a…
- Cannot add a same component multiple times. Already set at…
- Cannot add an entity to this entity manager when it is…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/01bc00833389cb51.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Engine/Engine/EntityManager.cs:223
processor.Draw(context);
}
}
}
flexibleProcessors.Draw(context);
}
/// <summary>
/// Adds the entity.
/// If the <see cref="Entity" /> has a parent, its parent should be added (or <see cref="TransformComponent.Children" />) should be used.
/// </summary>
/// <param name="entity">The entity.</param>
/// <exception cref="System.ArgumentException">Entity shouldn't have a parent.;entity</exception>
internal void Add(Entity entity)
{
// Entity can't be a root because it already has a parent?
if (entity.Transform != null && entity.Transform.Parent != null)
throw new ArgumentException("Entity shouldn't have a parent.", nameof(entity));
InternalAddEntity(entity);
}
/// <summary>
/// Adds the specified entity.
/// </summary>
/// <param name="entity">The entity to add.</param>
internal void InternalAddEntity(Entity entity)
{
// Already added?
if (entities.Contains(entity))
return;
if (entity.EntityManager != null)
{
throw new InvalidOperationException("Cannot add an entity to this entity manager when it is already used by another entity manager");
}View on GitHub (pinned to 96fad776d2)