Siccity / xNode

Unity Node Editor: Lets you view and edit node graphs inside Unity
MIT License
3.34k stars 591 forks source link

CustomNodeGraphEditor Doesn't work with abstract Classes #208

Closed jangofett890 closed 5 years ago

jangofett890 commented 5 years ago

While making a new graph type, I wanted to add a Node on startup (a blackboard, that I am porting from my own Node editor) but it appears none of the code in the editor is being called. This is my editor code, note that the file is in a folder named Editor. `

[CustomNodeGraphEditor(typeof(BlackBoardGraph))]
public abstract class BlackboardGraphEditor : NodeGraphEditor {
    public override void OnGUI() {
        base.OnGUI();
        Debug.Log("test");
    }

    public override void RemoveNode(Node node) {
        if (node.GetType() == typeof(Blackboard)) {
            return;
        }
        base.RemoveNode(node);
    }

    public override void OnCreate() {
        if (target.nodes.Where(node => node.GetType() == typeof(Blackboard)).First() == null) {
            CreateNode(typeof(Blackboard), new Vector2(0, 0));
            Debug.Log("create");
        } else {
            Debug.Log("should already have");
        }
    }
}`

Blackboardgraph is just a type that extends NodeGraph.

Not sure why this doesn't work, I've tried looking at the attribute code, but have no idea how it works. None of the Debugs are printing in the console, and the Node isn't being added to be specific.

jangofett890 commented 5 years ago

As it turns out, it's due to the class being Abstract, more of a compatibility thing now than a bug.

Siccity commented 5 years ago

I have modified the wiki page to include this https://github.com/Siccity/xNode/wiki/Graph-Editors