From 464929860530396920dee23e9a3f779c6143937c Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 23 May 2025 14:06:21 -0500 Subject: [PATCH] Dont allow setting prefab root name from scene instance. --- Source/Editor/CustomEditors/Dedicated/ActorEditor.cs | 2 +- Source/Editor/Modules/PrefabsModule.cs | 5 +++++ Source/Engine/Level/Prefabs/Prefab.Apply.cpp | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs b/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs index 062aeeedd..20acdf149 100644 --- a/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs @@ -316,7 +316,7 @@ namespace FlaxEditor.CustomEditors.Dedicated var childEditor = editor.ChildrenEditors[i]; // Special case for root actor transformation (can be applied only in Prefab editor, not in Level) - if (isActorEditorInLevel && childEditor.Values.Info.Name is "LocalPosition" or "LocalOrientation" or "LocalScale") + if (isActorEditorInLevel && childEditor.Values.Info.Name is "LocalPosition" or "LocalOrientation" or "LocalScale" or "Name") continue; var child = ProcessDiff(childEditor, !isScriptEditorWithRefValue); diff --git a/Source/Editor/Modules/PrefabsModule.cs b/Source/Editor/Modules/PrefabsModule.cs index d1b254200..617202062 100644 --- a/Source/Editor/Modules/PrefabsModule.cs +++ b/Source/Editor/Modules/PrefabsModule.cs @@ -255,12 +255,17 @@ namespace FlaxEditor.Modules // When applying changes to prefab from actor in level ignore it's root transformation (see ActorEditor.ProcessDiff) var originalTransform = instance.LocalTransform; + var originalName = instance.Name; if (instance.IsPrefabRoot && instance.HasScene) + { instance.LocalTransform = prefab.GetDefaultInstance().Transform; + instance.Name = prefab.GetDefaultInstance().Name; + } // Call backend var failed = PrefabManager.Internal_ApplyAll(FlaxEngine.Object.GetUnmanagedPtr(instance)); instance.LocalTransform = originalTransform; + instance.Name = originalName; if (failed) throw new Exception("Failed to apply the prefab. See log to learn more."); diff --git a/Source/Engine/Level/Prefabs/Prefab.Apply.cpp b/Source/Engine/Level/Prefabs/Prefab.Apply.cpp index 0df0723a2..4409ae161 100644 --- a/Source/Engine/Level/Prefabs/Prefab.Apply.cpp +++ b/Source/Engine/Level/Prefabs/Prefab.Apply.cpp @@ -1090,7 +1090,7 @@ bool Prefab::ApplyAllInternal(Actor* targetActor, bool linkTargetActorObjectToPr root = dynamic_cast(sceneObjects.Value->At(targetActorIdx)); } - // Try using the first actor without a parent as a new ro0t + // Try using the first actor without a parent as a new root for (int32 i = 1; i < sceneObjects->Count(); i++) { SceneObject* obj = sceneObjects.Value->At(i);