stride3d/stride · error · InvalidOperationException
This entity is another entity's child. Detach it before chan
Error message
This entity is another entity's child. Detach it before changing its scene.
What it means
Entity.Scene's setter throws InvalidOperationException when the entity still has a Transform.Parent (i.e. it is a child of another entity) and the caller attempts to assign a non-null scene. A child entity's scene is owned by its parent hierarchy, so you must detach it from its parent before re-parenting it into another scene. Assigning null while parented is allowed and simply detaches it via Transform.Parent = null.
Solutions
- Detach the entity from its parent first: entity.Transform.Parent = null; then assign entity.Scene.
- Remove the entity from its parent's Transform.Children (or use parent.Transform.Children.Remove(entity)) before changing Scene.
- If the intent was only to detach, assign null instead of a new scene.
Example fix
// before childEntity.Scene = targetScene; // throws while parented // after childEntity.Transform.Parent = null; childEntity.Scene = targetScene;
Defensive patterns
Strategy: validation
Validate before calling
if (entity.Transform.Parent != null)
entity.Transform.Parent = null; // detach first
entity.Scene = targetScene; Try / catch
try { entity.Scene = targetScene; }
catch (InvalidOperationException) { entity.Transform.Parent = null; entity.Scene = targetScene; } Prevention
- Always detach children (Transform.Parent = null) before moving entities between scenes.
- Wrap scene-reparenting in a MoveToScene(Entity, Scene) helper that handles detachment.
- Remember assigning Scene = null while parented only detaches; it does not re-parent.
When it happens
Trigger: Assigning entity.Scene = otherScene while entity.Transform.Parent != null; moving a child entity from one scene to another without first removing it from its parent.
Common situations: Runtime scene streaming/reparenting code that moves entities between scenes, dragging entities between scenes in the editor while they are nested, or procedural level building that forgets to detach children first.
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
- Could not find child entity named {0}
- This scene's parent is not the expected value.
- Could not find asset {0} for bundle {1}
- Expect name1=value1;name2=value2 format.
- assetItem must be an absolute path
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/bc5f47ddb553e88d.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Engine/Engine/Entity.cs:111
}
/// <summary>
/// The scene this entity is in. <br/>
/// Setting this to null will remove the entity from the scene and detach it from its parent if it has one.
/// </summary>
[DataMemberIgnore]
public Scene Scene
{
get
{
return this.FindRoot().SceneValue;
}
set
{
if (Transform.Parent != null)
{
if (value != null)
throw new InvalidOperationException("This entity is another entity's child. Detach it before changing its scene.");
Transform.Parent = null;
return;
}
var oldScene = SceneValue;
if (oldScene == value)
return;
oldScene?.Entities.Remove(this);
value?.Entities.Add(this);
}
}
/// <summary>
/// The entity manager which processes this entity.
/// </summary>View on GitHub (pinned to 96fad776d2)