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

  1. Add the candidate parent to a scene (via scene.Add / AddChild / AddComponent) before using it as a parent.
  2. Verify `value.IScene != null` before assigning Parent.
  3. 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

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


AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13). Data as JSON: /api/errors/1434ef2ec9307bc8. Report an issue: GitHub.