From efa963be683f98a5f2fec0e9d4dfbad2cb67d8aa Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 13 Oct 2025 21:45:31 +0200 Subject: [PATCH] Fix editor error when prefab asset is unloaded --- Source/Editor/Viewport/PrefabWindowViewport.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Source/Editor/Viewport/PrefabWindowViewport.cs b/Source/Editor/Viewport/PrefabWindowViewport.cs index 39c126c37..362aeacf6 100644 --- a/Source/Editor/Viewport/PrefabWindowViewport.cs +++ b/Source/Editor/Viewport/PrefabWindowViewport.cs @@ -257,16 +257,23 @@ namespace FlaxEditor.Viewport /// public void SaveActiveUIScalingOption() { - var defaultKey = $"{Prefab.ID}:DefaultViewportScalingIndex"; + if (!Prefab) + return; + var id = Prefab.ID; + var defaultKey = $"{id}:DefaultViewportScalingIndex"; Editor.Instance.ProjectCache.SetCustomData(defaultKey, _defaultScaleActiveIndex.ToString()); - var customKey = $"{Prefab.ID}:CustomViewportScalingIndex"; + var customKey = $"{id}:CustomViewportScalingIndex"; Editor.Instance.ProjectCache.SetCustomData(customKey, _customScaleActiveIndex.ToString()); } private void LoadCustomUIScalingOption() { + if (!Prefab) + return; + var id = Prefab.ID; Prefab.WaitForLoaded(); - var defaultKey = $"{Prefab.ID}:DefaultViewportScalingIndex"; + + var defaultKey = $"{id}:DefaultViewportScalingIndex"; if (Editor.Instance.ProjectCache.TryGetCustomData(defaultKey, out string defaultData)) { if (int.TryParse(defaultData, out var index)) @@ -286,7 +293,7 @@ namespace FlaxEditor.Viewport } } - var customKey = $"{Prefab.ID}:CustomViewportScalingIndex"; + var customKey = $"{id}:CustomViewportScalingIndex"; if (Editor.Instance.ProjectCache.TryGetCustomData(customKey, out string data)) { if (int.TryParse(data, out var index))