egametang/ET · error · Exception
cant set parent self: {this.GetType().FullName}
Error message
cant set parent self: {this.GetType().FullName} What it means
Thrown by the Entity.Parent setter when the assigned value is the entity itself (value == this). The ECS forbids an entity being its own parent, which would create a cycle in the tree.
Source
Thrown at Packages/cn.etetet.core/Scripts/Core/Share/Entity/Entity.cs:200
[AllowEntityMember]
private Entity parent;
// 可以改变parent,但是不能设置为null
[MemoryPackIgnore]
[BsonIgnore]
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);View on GitHub (pinned to 5cab01f7a8)
Solutions
- Skip the assignment when the candidate parent is the entity itself.
- In bulk reparent routines, exclude the destination node from the source set.
- Add an early `if (value == this) return;` guard in your own reparent helper.
Example fix
// before
foreach (var child in group.Children)
{
child.Parent = newParent; // newParent may equal child
}
// after
foreach (var child in group.Children)
{
if (child == newParent) continue;
child.Parent = newParent;
} Defensive patterns
Strategy: validation
Validate before calling
if (newParent != null && newParent != entity)
{
entity.Parent = newParent;
} Prevention
- Exclude the destination node from bulk reparent sets.
- Add `value == this` guards in custom reparent helpers.
- Validate identity before assigning Parent.
When it happens
Trigger: Assigning `entity.Parent = entity`; reparenting a list where the loop variable accidentally equals the entity; a generic 'reparent all children onto X' routine where X is one of the children.
Common situations: Bulk reparenting over a collection that includes the destination; UI/hierarchy tooling that re-parents a node onto itself; copy-paste of reparent code without excluding self.
Related errors
- cant set parent null: {this.GetType().FullName}
- cant set parent because parent iSence is null: {this.GetType
- 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/267a72562a707faa.
Report an issue: GitHub.