diff --git a/Source/Editor/CustomEditors/CustomEditor.cs b/Source/Editor/CustomEditors/CustomEditor.cs index caf03bc2f..c1c004d43 100644 --- a/Source/Editor/CustomEditors/CustomEditor.cs +++ b/Source/Editor/CustomEditors/CustomEditor.cs @@ -142,6 +142,10 @@ namespace FlaxEditor.CustomEditors /// public void RebuildLayout() { + // Skip rebuilding during init + if (CurrentCustomEditor == this) + return; + // Special case for root objects to run normal layout build if (_presenter.Selection == Values) { diff --git a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs index dd43de1ee..b860d9826 100644 --- a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs @@ -412,8 +412,6 @@ namespace FlaxEditor.CustomEditors.Dedicated public override void Initialize(LayoutElementsContainer layout) { _cachedType = null; - if (Values.HasNull) - return; if (HasDifferentTypes) { // TODO: support stable editing multiple different control types (via generic way or for transform-only) @@ -626,8 +624,6 @@ namespace FlaxEditor.CustomEditors.Dedicated { RebuildLayout(); } - - //RefreshValues(); } base.Refresh(); @@ -663,39 +659,32 @@ namespace FlaxEditor.CustomEditors.Dedicated cm.Show(button.Parent, button.BottomLeft); } + private void SetType(ref ScriptType controlType, UIControl uiControl) + { + string previousName = uiControl.Control?.GetType().Name ?? nameof(UIControl); + uiControl.Control = (Control)controlType.CreateInstance(); + if (uiControl.Name.StartsWith(previousName)) + { + string newName = controlType.Name + uiControl.Name.Substring(previousName.Length); + uiControl.Name = StringUtils.IncrementNameNumber(newName, x => uiControl.Parent.GetChild(x) == null); + } + } + private void SetType(ScriptType controlType) { var uiControls = ParentEditor.Values; - if (Presenter.Undo != null) + if (Presenter.Undo?.Enabled ?? false) { using (new UndoMultiBlock(Presenter.Undo, uiControls, "Set Control Type")) { for (int i = 0; i < uiControls.Count; i++) - { - var uiControl = (UIControl)uiControls[i]; - string previousName = uiControl.Control?.GetType().Name ?? nameof(UIControl); - uiControl.Control = (Control)controlType.CreateInstance(); - if (uiControl.Name.StartsWith(previousName)) - { - string newName = controlType.Name + uiControl.Name.Substring(previousName.Length); - uiControl.Name = StringUtils.IncrementNameNumber(newName, x => uiControl.Parent.GetChild(x) == null); - } - } + SetType(ref controlType, (UIControl)uiControls[i]); } } else { for (int i = 0; i < uiControls.Count; i++) - { - var uiControl = (UIControl)uiControls[i]; - string previousName = uiControl.Control?.GetType().Name ?? nameof(UIControl); - uiControl.Control = (Control)controlType.CreateInstance(); - if (uiControl.Name.StartsWith(previousName)) - { - string newName = controlType.Name + uiControl.Name.Substring(previousName.Length); - uiControl.Name = StringUtils.IncrementNameNumber(newName, x => uiControl.Parent.GetChild(x) == null); - } - } + SetType(ref controlType, (UIControl)uiControls[i]); } ParentEditor.RebuildLayout(); diff --git a/Source/Editor/CustomEditors/Values/ValueContainer.cs b/Source/Editor/CustomEditors/Values/ValueContainer.cs index 49d3b5591..9bdbc4bcf 100644 --- a/Source/Editor/CustomEditors/Values/ValueContainer.cs +++ b/Source/Editor/CustomEditors/Values/ValueContainer.cs @@ -255,8 +255,15 @@ namespace FlaxEditor.CustomEditors if (instanceValues._referenceValue == null && !instanceValues.Type.IsValueType) return; - _referenceValue = Info.GetValue(instanceValues._referenceValue); - _hasReferenceValue = true; + try + { + _referenceValue = Info.GetValue(instanceValues._referenceValue); + _hasReferenceValue = true; + } + catch + { + // Ignore error if reference value has different type or is invalid for this member + } } }