From 21edb43bb1a72773c86d4b09ea3295b2584a555d Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 4 Mar 2024 21:04:15 +0100 Subject: [PATCH] Fix creating prefab out of actor to reset local transform of it for better instancing #1545 --- Source/Editor/Content/Proxy/PrefabProxy.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/Editor/Content/Proxy/PrefabProxy.cs b/Source/Editor/Content/Proxy/PrefabProxy.cs index 0c0114fa8..ee3674daa 100644 --- a/Source/Editor/Content/Proxy/PrefabProxy.cs +++ b/Source/Editor/Content/Proxy/PrefabProxy.cs @@ -75,6 +75,8 @@ namespace FlaxEditor.Content /// public override void Create(string outputPath, object arg) { + bool resetTransform = false; + var transform = Transform.Identity; if (!(arg is Actor actor)) { // Create default prefab root object @@ -86,8 +88,17 @@ namespace FlaxEditor.Content // Cleanup it after usage Object.Destroy(actor, 20.0f); } + else if (actor.Scene != null) + { + // Create prefab with identity transform so the actor instance on a level will have it customized + resetTransform = true; + transform = actor.LocalTransform; + actor.LocalTransform = Transform.Identity; + } PrefabManager.CreatePrefab(actor, outputPath, true); + if (resetTransform) + actor.LocalTransform = transform; } ///