Search Unity

GraphView Edges

Discussion in 'UI Toolkit' started by Wuceng, May 29, 2019.

  1. Wuceng

    Wuceng

    Joined:
    Dec 18, 2018
    Posts:
    9
    Hey,

    I am trying to set up my own node based editor using the elements from the graphview API. I got pretty far by reading the Code of the Shadergraph repo but documentation in general is lacking. Now I am able to create nodes and move them around but I can't really figure out on how all of the edge related classes (Edge, EdgeConnector,...) work together. Does anyone have experience with creating edges or how to create an edge by dragging from a Port on a Node? Any help or directions would be greatly appreciated.
     
  2. wbahnassi_unity

    wbahnassi_unity

    Unity Technologies

    Joined:
    Mar 12, 2018
    Posts:
    28
    From what I can see, you don't need to handle edges yourself if you have nodes with ports on them. All you need is an extension to the NodeAdapter to tell whether a certain port can accept connection from another port. The system handles the gritty details of dragging/dropping..etc.
    I can't seem to find a public documentation for the extension mechanism, but it seems you need to expose a public static method with the attribute [Extension], and it takes three parameters: (NodeAdapter adapter, object a, object b) and returns a bool to tell whether the connection is allowed or not.

    I hope this helps.
     
    Kirsche likes this.
  3. Wuceng

    Wuceng

    Joined:
    Dec 18, 2018
    Posts:
    9
    Thank you for your help. I tried what you said but found out it is not necessary to have an extension method. But the mention of the NodeAdapter helped me find what I was missing. After searching the shader graph repo for its usage I noticed that I forgot to override the GetCompatiblePorts method on my GraphView and thus it didn't allow for connections. Everything works perfectly now.
    Kudos to the team behind the GraphView API. It's really easy to use but needs better docs.
     
    cielbird likes this.