How can I display a scriptable object in a custom editor ?
Hello,
I'm creating a custom editor for some state machine. For the logic behind my state machine, I created a bunch of classes (StochasticBehaviour, SubBehaviour and Behaviour). For trivial machine, it is possible to edit all of this in the inspector but it quickly become overcrowded there. ;)
Hence the need to create these state machine. However I can't find how to display the properties of the Behaviour in the custom editor. EditorGUI.ObjectField
raises an error and so does EditorGUILayout.ObjectField
.
Has anyone done this before ? Any tips ? Thanks !
Answer by Lukas-Wendt · Apr 18, 2018 at 06:17 PM
You can create an editor in OnEnable with Editor.CreateEditor(your scriptable object), and afterwards you can call OnInspectorGUI on that newly created editor.
using UnityEditor;
public class CustomEditorWindow : EditorWindow
{
private Editor m_MyScriptableObjectEditor;
private MyScriptableObject m_MyScriptableObject;
private void OnEnable()
{
// Get a reference to your scriptable object.
// m_MyScriptableObject = ...
m_MyScriptableObjectEditor = Editor.CreateEditor(m_MyScriptableObject);
}
private void OnGUI()
{
m_MyScriptableObjectEditor.OnInspectorGUI();
}
}
Your answer
Follow this Question
Related Questions
Editor Int sliders affecting each other 0 Answers
How to change the text of EditorGUILayout.TextField 2 Answers
GUİ Editor Window input 0 Answers
Vertical Foldout in Editor Window 0 Answers
How to make my scene object reference survive the button play 1 Answer