I have a GameObject with a reference to a ScriptableObject that has a UI Toolkit Editor. The goal is to draw that Editor if the ScriptableObject is assigned. With IMGUI I used this approach:
[CustomEditor(typeof(MyClass))]
class MyEditor : Editor
{
MyClass myClass;
private void OnEnable()
{
myClass = (MyClass)target;
}
public override void OnInspectorGUI()
{
Editor editor = CreateEditor(myClass.scriptable);
editor.OnInspectorGUI();
}
}
With UI Toolkit I tried this, but the Editor seems detached from the ScriptableObject:
[CustomEditor(typeof(MyClass))]
class MyEditor : Editor
{
MyClass myClass;
private void OnEnable()
{
myClass = (MyClass)target;
}
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
var editor = CreateEditor(myClass.scriptable);
root.Add(editor.CreateInspectorGUI());
return root;
}
}
All of the values are default values and no changes are saved. Any idea on how to get this to work?