,Unity Custom Inspector CreateInspectorGUI redraw on change
I am working with the new UIElements version of the inspector initialization routine, using CreateInspectorGUI() and I have it displaying the way I want. The problem comes in when I make a change to the object as a result of a button press in the inspector, I can't get the inspector to repaint to reflect the changes no matter what I try.
I've tried Repaint(), I've tried overriding RequiresConstantRepaint() and returning true, I've tried calling MarkDirtyRepaint on my instance. I'm at my wits end as I can't find anything on this problem
Can anyone more experienced in this please give me a hand please?
Unity Version is 2019.2.2f1
Here is my inspector
[CustomEditor(typeof(ActionListRunner))]
public class GameActionListInspector : Editor
{
public override bool RequiresConstantRepaint()
{
return false;
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
}
public override VisualElement CreateInspectorGUI()
{
ActionListRunner runner = (ActionListRunner) target;
if (runner.ListActions == null)
{
runner.ListActions = new List<BaseGameAction>();
}
var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Editor/GameActionListInspector.uxml");
var uxmlVE = visualTree.CloneTree();
uxmlVE.styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Editor/GameActionListInspector.uss"));
EnumField typeToCreate = uxmlVE.Query<EnumField>("ActionType");
Button addAction = new Button(()=>
{
ActionType type = (ActionType) typeToCreate.value;
if (type == ActionType.MessageBox)
{
runner.ListActions.Add(ScriptableObject.CreateInstance<ShowMessageBox>());
uxmlVE.MarkDirtyRepaint();
}
});
addAction.text = "Test";
uxmlVE.Add(addAction);
//addAction.clickable = new Clickable(btnAddAction);
VisualElement actionsElement = uxmlVE.Query<VisualElement>("actions");
int i = 0;
foreach (var gameAction in runner.ListActions)
{
Label label = new Label($"{i+1} - {gameAction.Type.ToString()}");
actionsElement.Add(label);
if (gameAction is ShowMessageBox)
{
InspectorElement element = new InspectorElement((ShowMessageBox)gameAction);
actionsElement.Add(element);
}
Button btnDelete = new Button(() =>
{
runner.ListActions.Remove(gameAction);
uxmlVE.MarkDirtyRepaint();
});
btnDelete.text = $"Remove {label.text}";
actionsElement.Add(btnDelete);
i++;
}
return uxmlVE;
}
}
Here is my UXML
<?xml version="1.0" encoding="utf-8"?>
<UXML xmlns:ui="UnityEngine.UIElements" xmlns:ue="UnityEditor.UIElements">
<ui:VisualElement class="gameActionList">
<ui:Label text="Action List Editor" />
<ui:ScrollView name="actions" class="cmd" mode="Vertical">
</ui:ScrollView>
<ue:EnumField class="menu__item" name="ActionType" type="Assets.ActionType, Assembly-CSharp" value="SaveGame" />
</ui:VisualElement>
</UXML>
Answer by dan-kostin · Feb 04, 2020 at 01:07 PM
I've found how to work with custom List element in custom inspector with updating it. https://forum.unity.com/threads/uielements-listview-with-serializedproperty-of-an-array.719570/#post-4824431
Your answer
Follow this Question
Related Questions
How to create a drop down menu in editor inspector 0 Answers
Loading Json from Resources via Editor Script 1 Answer
Generic component reference 0 Answers
How to save a two-dimensional array, as part of the variable inspector? 0 Answers
CustomEditor on Inspector, Text too big to be fully rendered 0 Answers