I am trying to make a custom editor window to make a node-editor for the AI in my game. Currently the nodes themselves are displaying nicely (with one or two little bugs), but the object fields I have on each node aren’t working. I have a base class script called “State” which is meant to represent an AI State:
[System.Serializable]
public class State : ScriptableObject
{
public StateIDs _id;
[SerializeField]private List<TransitionBase> _availableTransitions;
//some irrelevent code
}
and then the node is a class which looks like this:
namespace Assets._Custom._Scripts._Editor
{
[System.Serializable]
public class Node
{
public int _id;
public Rect _box;
public State _state;
public FSMNodeEditor _owner;
public Node(int ID, Rect rect, State initState, FSMNodeEditor owner)
{
_id = ID;
_box = rect;
_state = initState;
_owner = owner;
}
public Node(int ID, Rect rect, FSMNodeEditor owner)
{
_id = ID;
_box = rect;
_state = (State)ScriptableObject.CreateInstance(typeof(State));
_owner = owner;
}
public Node(Rect rect, FSMNodeEditor owner)
{
_id = 0;
_box = rect;
_state = (State)ScriptableObject.CreateInstance(typeof(State));
_owner = owner;
}
public Node(FSMNodeEditor owner)
{
_id = 0;
_box = new Rect();
_state = (State)ScriptableObject.CreateInstance(typeof(State));
_owner = owner;
}
public void DrawNode(int id)
{
EditorGUILayout.ObjectField(_state, typeof(State), false);
if(id != _id)
{
Debug.LogError("Given ID and Node ID do not match");
return;
}
if(GUILayout.Button("Join Node"))
{
_owner.JoinNode(id);
}
if(GUILayout.Button("Delete Node"))
{
_owner.NodeDeleted(id);
}
GUI.DragWindow();
}
}
}
As you can see, I am trying to use EditorGUILayout.ObjectField to enable me to choose a State to edit in that Node. Problem is, when I create a node in the editor window and click on the button on the object field, no States pop up. There is nothing to choose. I tried making a “TestState” derived from the base State class, but no luck. It just says “None” when I try to choose a State. I even tried dragging TestState onto the object field, but it didn’t let me put it in there.
So what is going wrong? Is it because State is a ScriptableObject?
Thank you for any help.