diff --git a/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs b/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs index db77e24e7..3699b8254 100644 --- a/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs @@ -245,9 +245,7 @@ namespace FlaxEditor.CustomEditors.Dedicated { // Special case for new Script added to actor if (editor.Values[0] is Script script && !script.HasPrefabLink) - { return CreateDiffNode(editor); - } // Skip if no change detected var isRefEdited = editor.Values.IsReferenceValueModified; @@ -258,9 +256,16 @@ namespace FlaxEditor.CustomEditors.Dedicated if (editor.ChildrenEditors.Count == 0 || (isRefEdited && editor is CollectionEditor)) result = CreateDiffNode(editor); bool isScriptEditorWithRefValue = editor is ScriptsEditor && editor.Values.HasReferenceValue; + bool isActorEditorInLevel = editor is ActorEditor && editor.Values[0] is Actor actor && actor.IsPrefabRoot && actor.Scene != null; for (int i = 0; i < editor.ChildrenEditors.Count; i++) { - var child = ProcessDiff(editor.ChildrenEditors[i], !isScriptEditorWithRefValue); + 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") + continue; + + var child = ProcessDiff(childEditor, !isScriptEditorWithRefValue); if (child != null) { if (result == null) @@ -276,7 +281,6 @@ namespace FlaxEditor.CustomEditors.Dedicated { var prefabObjectScript = prefabObjectScripts[j]; bool isRemoved = true; - for (int i = 0; i < editor.ChildrenEditors.Count; i++) { if (editor.ChildrenEditors[i].Values is ScriptsEditor.ScriptsContainer container && container.PrefabObjectId == prefabObjectScript.PrefabObjectID) @@ -286,14 +290,12 @@ namespace FlaxEditor.CustomEditors.Dedicated break; } } - if (isRemoved) { var dummy = new RemovedScriptDummy { PrefabObject = prefabObjectScript }; - var child = CreateDiffNode(dummy); if (result == null) result = CreateDiffNode(editor); diff --git a/Source/Editor/Modules/PrefabsModule.cs b/Source/Editor/Modules/PrefabsModule.cs index 5cd212db0..e0e464c04 100644 --- a/Source/Editor/Modules/PrefabsModule.cs +++ b/Source/Editor/Modules/PrefabsModule.cs @@ -225,8 +225,15 @@ namespace FlaxEditor.Modules throw new ArgumentException("Missing prefab to apply."); PrefabApplying?.Invoke(prefab, instance); + // When applying changes to prefab from actor in level ignore it's root transformation (see ActorEditor.ProcessDiff) + var originalTransform = instance.LocalTransform; + if (instance.IsPrefabRoot && instance.Scene != null) + instance.LocalTransform = prefab.GetDefaultInstance().Transform; + // Call backend - if (PrefabManager.Internal_ApplyAll(FlaxEngine.Object.GetUnmanagedPtr(instance))) + var failed = PrefabManager.Internal_ApplyAll(FlaxEngine.Object.GetUnmanagedPtr(instance)); + instance.LocalTransform = originalTransform; + if (failed) throw new Exception("Failed to apply the prefab. See log to learn more."); PrefabApplied?.Invoke(prefab, instance);