egametang/ET · error · Exception
cant set parent because parent iSence is null: {this.GetType
Error message
cant set parent because parent iSence is null: {this.GetType().FullName} {value.GetType().FullName} What it means
Thrown by Entity.Parent setter when the candidate parent's IScene is null — i.e. the target parent is not attached to any scene (not on the data tree). The ECS strictly requires a parent to belong to a scene so children inherit scene membership transitively.
Source
Thrown at Packages/cn.etetet.core/Scripts/Core/Share/Entity/Entity.cs:206
public Entity Parent
{
get => this.parent;
protected set
{
if (value == null)
{
throw new Exception($"cant set parent null: {this.GetType().FullName}");
}
if (value == this)
{
throw new Exception($"cant set parent self: {this.GetType().FullName}");
}
// 严格限制parent必须要有iSence,也就是说parent必须在数据树上面
if (value.IScene == null)
{
throw new Exception($"cant set parent because parent iSence is null: {this.GetType().FullName} {value.GetType().FullName}");
}
if (this.parent != null) // 之前有parent
{
// parent相同,不设置
if (this.parent == value)
{
Log.Error($"重复设置了Parent: {this.GetType().FullName} parent: {this.parent.GetType().FullName}");
return;
}
this.parent.RemoveChild(this.Id, false);
}
this.parent = value;
this.IsComponent = false;
this.parent.AddToChildren(this);
View on GitHub (pinned to 5cab01f7a8)
Solutions
- Add the candidate parent to a scene (via scene.Add / AddChild / AddComponent) before using it as a parent.
- Verify `value.IScene != null` before assigning Parent.
- Ensure you are not parenting onto an entity from an already-disposed scene.
Example fix
// before var host = ObjectPool.Instance.Fetch(typeof(HostEntity)); child.Parent = host; // host not in any scene yet // after scene.Add(host); child.Parent = host;
Defensive patterns
Strategy: validation
Validate before calling
if (newParent != null && newParent.IScene != null)
{
entity.Parent = newParent;
} Prevention
- Attach the candidate parent to a scene (scene.Add) before parenting.
- Verify newParent.IScene != null before reparenting.
- Avoid reparenting onto entities from disposed scenes.
When it happens
Trigger: Reparenting onto an entity that was created but never added to a scene; parenting onto an entity whose scene was disposed; parenting onto a just-instantiated Entity before it is attached to a Scene.
Common situations: Creating an Entity with `new` / ObjectPool then trying to parent it before calling scene.Add; entities instantiated during deserialization before the scene graph is wired; reparenting after the owning scene was torn down.
Related errors
- cant set parent null: {this.GetType().FullName}
- cant set parent self: {this.GetType().FullName}
- iScene cant set null: {this.GetType().FullName}
- entity already has component: {type.FullName}
- entity is disposed, instanceid == 0!
AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13).
Data as JSON: /api/errors/1434ef2ec9307bc8.
Report an issue: GitHub.