Search Unity

GraphView port to port information transfer

Discussion in 'UI Toolkit' started by GameSmith2020, Apr 15, 2020.

  1. GameSmith2020

    GameSmith2020

    Joined:
    Jul 14, 2018
    Posts:
    3
    Hey, I am making a node editor, using GraphView, and have been struggling with something that I swear I must have missed somewhere, as this seems like something that would be basic functionality; I cannot seem to get any data passing through the Port's to one another. I am assuming (probably wrongly) that port.source would have something to do with it, but I do not know how that works in to everything.

    I currently have working, different data types and their storage, along with the input methods, using the TextField, FloatField, etc. But I just can't figure out how to get them to talk to each other. Any help on this would be awesome.
     
  2. GameSmith2020

    GameSmith2020

    Joined:
    Jul 14, 2018
    Posts:
    3
    So I have figured out a way around this, but it is using reflection... that's probably fine right? For anyone struggling with this, I had to create new Port and Node classes inheriting from them, then added a RegisterValueChangeCallback to the input field that would run a function to check to see if the port connected to the field was connected to anything, and if it was, update the variable that I added to the port class to watch. Not exactly elegant, if anyone has a better idea, I am all ears (or eyes as this is a written medium)
     
  3. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    650
    "I cannot seem to get any data passing through the Port's to one another."
    Well as far as I can tell, GraphView is just a "View", as these are all Editor only Classes, the functionality should be handled somewhere else.
    Basic setup is:
    GraphData : ScriptableObject --> stores your nodes, node positions and so on
    RuntimeLogic : MonoBehaviour --> can Load and execute data from GraphData
    GraphView & GraphEditorWindow --> Save&Load to GraphData, visualizes the graph but does not execute any logic
     
  4. dev_reimu

    dev_reimu

    Joined:
    Jun 24, 2017
    Posts:
    10
    Anyone found a solution to this?
     
  5. felipemullen

    felipemullen

    Joined:
    Mar 4, 2017
    Posts:
    44
    I am working with graph view and doing essentially what @Hannibal_Leo mentioned above. It might depend on your needs.
    I have created a graph view that creates/modifies a scriptable object. This object can be read at runtime by other game logic, so in terms of "passing data", the logic is independent of the graph:

    - Each node has an `OnExit` callback that can return a known data type
    - Each node also has an `OnEnter` callback that accepts that same data type