diff --git a/Content.Server/Maps/MapMigrationSystem.cs b/Content.Server/Maps/MapMigrationSystem.cs index ce11f15fdb..f0c19e1414 100644 --- a/Content.Server/Maps/MapMigrationSystem.cs +++ b/Content.Server/Maps/MapMigrationSystem.cs @@ -4,6 +4,7 @@ using System.Linq; using Robust.Server.GameObjects; using Robust.Server.Maps; using Robust.Shared.ContentPack; +using Robust.Shared.Map.Events; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Markdown; using Robust.Shared.Serialization.Markdown.Mapping; diff --git a/Content.Shared/Follower/FollowerSystem.cs b/Content.Shared/Follower/FollowerSystem.cs index 9547cca0ce..b7dbb28cf9 100644 --- a/Content.Shared/Follower/FollowerSystem.cs +++ b/Content.Shared/Follower/FollowerSystem.cs @@ -5,6 +5,7 @@ using Content.Shared.Movement.Events; using Content.Shared.Movement.Systems; using Content.Shared.Verbs; using Robust.Shared.Map; +using Robust.Shared.Map.Events; using Robust.Shared.Utility; namespace Content.Shared.Follower; @@ -20,6 +21,25 @@ public sealed class FollowerSystem : EntitySystem SubscribeLocalEvent>(OnGetAlternativeVerbs); SubscribeLocalEvent(OnFollowerMove); SubscribeLocalEvent(OnFollowedTerminating); + SubscribeLocalEvent(OnBeforeSave); + } + + private void OnBeforeSave(BeforeSaveEvent ev) + { + // Some followers will not be map savable. This ensures that maps don't get saved with empty/invalid + // followers, but just stopping any following on the map being saved. + + var query = AllEntityQuery(); + while (query.MoveNext(out var uid, out var follower, out var xform, out var meta)) + { + if (meta.EntityPrototype == null || meta.EntityPrototype.MapSavable) + continue; + + if (xform.MapUid != ev.Map) + continue; + + StopFollowingEntity(uid, follower.Following); + } } private void OnGetAlternativeVerbs(GetVerbsEvent ev)