Add transform recursion check (#3983)

This commit is contained in:
Leon Friedrich
2023-05-01 16:11:21 +12:00
committed by GitHub
parent 2efed72eba
commit 381c856dd4

View File

@@ -472,6 +472,21 @@ public abstract partial class SharedTransformSystem
QueueDel(uid);
throw new InvalidOperationException($"Attempted to re-parent to a terminating object. Entity: {ToPrettyString(uid)}, new parent: {ToPrettyString(value.EntityId)}");
}
// TODO maybe don't wrap this in DEBUG check once querying components is faster.
#if DEBUG
if (xform.MapUid == newParent.MapUid)
{
var recursiveXform = newParent;
while (recursiveXform.ParentUid.IsValid())
{
if (recursiveXform.ParentUid == uid)
throw new InvalidOperationException($"Attempted to parent an entity to one of its descendants! {ToPrettyString(uid)}");
recursiveXform = xformQuery.GetComponent(recursiveXform.ParentUid);
}
}
#endif
}
if (xform._parent.IsValid())