Fix follower recursion

This commit is contained in:
Kara D
2022-02-19 16:55:29 -07:00
parent fe6e7cf1fd
commit 99d44ee388
3 changed files with 11 additions and 1 deletions

View File

@@ -63,11 +63,16 @@ public sealed class FollowerSystem : EntitySystem
/// <param name="entity">The entity to be followed</param>
public void StartFollowingEntity(EntityUid follower, EntityUid entity)
{
// No recursion for you
if (Transform(entity).ParentUid == follower)
return;
var followerComp = EnsureComp<FollowerComponent>(follower);
followerComp.Following = entity;
var followedComp = EnsureComp<FollowedComponent>(entity);
followedComp.Following.Add(follower);
if (!followedComp.Following.Add(follower))
return;
var xform = Transform(follower);
xform.AttachParent(entity);