Search Unity

GraphView Edges

Discussion in 'UIElements' started by Wutseng, May 29, 2019.

  1. Wutseng

    Wutseng

    Joined:
    Dec 18, 2018
    Posts:
    2
    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:
    18
    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.
     
  3. Wutseng

    Wutseng

    Joined:
    Dec 18, 2018
    Posts:
    2
    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.