diff --git a/Distance.LevelMods/CustomObjectManager.cs b/Distance.LevelMods/CustomObjectManager.cs index d9422ff..5f21b39 100644 --- a/Distance.LevelMods/CustomObjectManager.cs +++ b/Distance.LevelMods/CustomObjectManager.cs @@ -72,7 +72,11 @@ public static void Register(SerialComponent entryComp, byte[] data) { BinaryDeserializer.idToSerializableTypeMap_[entryComp.ID_] = entryComp.GetType(); var root = man.LevelPrefabFileInfosRoot_; - root.AddChildInfo(new LevelPrefabFileInfo(entryComp.name, entryComp.gameObject, root)); + var info = new LevelPrefabFileInfo(entryComp.name, entryComp.gameObject, root); + if (root.childInfos_.RemoveAll(info1 => info1.Name_ == info.Name_) > 0) + G.Sys.LevelEditor_.DoFramesLater(2, () => G.Sys.LevelEditor_.SetToolText( + $"Updated prefab for custom object {entryComp.name}")); + root.AddChildInfo(info); } } } diff --git a/Distance.LevelMods/Entry.cs b/Distance.LevelMods/Entry.cs index 977f896..7a23057 100644 --- a/Distance.LevelMods/Entry.cs +++ b/Distance.LevelMods/Entry.cs @@ -17,9 +17,11 @@ public void Initialize(IManager manager) { G.Sys.LevelEditor_.AddEventToRegisteredHotKeys(InputEvent.Create("ctrl+shift+o"), LoadCustomObjectTool.info.Name_)); - PostLoad.Subscribe(data => + PostLoad.Subscribe(data => { // remove custom object manager when a level loads - data.level_.TryDeleteLayer(data.level_.GetLayer(nameof(CustomObjectManager)), true)); + var layer = data.level_.GetLayer(nameof(CustomObjectManager)); + if (layer != null) data.level_.TryDeleteLayer(layer, true); + }); RuntimePatcher.AutoPatch(); } diff --git a/Distance.LevelMods/Harmony.cs b/Distance.LevelMods/Harmony.cs index 0fe7ddd..eef56a2 100644 --- a/Distance.LevelMods/Harmony.cs +++ b/Distance.LevelMods/Harmony.cs @@ -39,6 +39,8 @@ namespace Level_ { internal static class SaveToPath { [UsedImplicitly] private static void Prefix(Level __instance) { + if (__instance.FindComponentsOfType().IsNullOrEmpty()) return; + var le = G.Sys.levelEditor_!; var prefab = G.Sys.ResourceManager_.levelPrefabs_[nameof(CustomObjectManager)];