Prevent follower recursion (#15921)

This commit is contained in:
Leon Friedrich
2023-04-30 13:44:14 +12:00
committed by GitHub
parent 818f23352e
commit b05343045f

View File

@@ -65,9 +65,15 @@ public sealed class FollowerSystem : EntitySystem
public void StartFollowingEntity(EntityUid follower, EntityUid entity)
{
// No recursion for you
if (Transform(entity).ParentUid == follower)
var targetXform = Transform(entity);
while (targetXform.ParentUid.IsValid())
{
if (targetXform.ParentUid == follower)
return;
targetXform = Transform(targetXform.ParentUid);
}
var followerComp = EnsureComp<FollowerComponent>(follower);
followerComp.Following = entity;