Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

xNode - A general purpose node editor

Discussion in 'Assets and Asset Store' started by Siccity, Oct 30, 2017.

  1. CptKen

    CptKen

    Joined:
    May 30, 2017
    Posts:
    216
    Thanks I'll give it a try
     
  2. Dizy

    Dizy

    Joined:
    Aug 22, 2015
    Posts:
    13
    Hi Siccity, i have release my utility ai framework based on your awesome xNode. I mainly use it for my projects but i decided to do some documentation for my students.

    Of course i credited you.

    https://github.com/FBast/xNodeUtilityAI/wiki
     
    Siccity likes this.
  3. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Nice work! :)
    I added a link to your project in the wiki
     
  4. neoneper

    neoneper

    Joined:
    Nov 14, 2013
    Posts:
    48
    Hi. Could you help me?.
    How i can add an toolbar menu at graphNode windows?.

    I can see in any preentScreen that you do it, but i no can see where there it in your codes.
    (^.~)
     
  5. crazymahone

    crazymahone

    Joined:
    Mar 17, 2017
    Posts:
    7
    Is there a super simple example showing the creation of a graph at runtime? I know there is Example scene, but it seems to also support for the Unity Editor component which is something I don't need.
     
  6. neoneper

    neoneper

    Joined:
    Nov 14, 2013
    Posts:
    48
    On version 1.7, there is folder "examples", and inside there is a runtime sample.
     
  7. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    You can override OnGUI in a custom graph editor and draw it like you normally would
     
  8. neoneper

    neoneper

    Joined:
    Nov 14, 2013
    Posts:
    48
    Oyea, i already did that. But the real problem is the zoom. I can not position the Gui in top, because the zoom of the grid reposition the rect of the the gui components. I tried used Guilayout, Gui with rect and calculate de real position using the function GridToWindows and WindowsToGrid too. But not work
     
  9. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    So much power, I like it!
     
    Siccity likes this.
  10. Dizy

    Dizy

    Joined:
    Aug 22, 2015
    Posts:
    13
    Hi again Siccity, do you plan a way to group nodes with larger node with a title ? It could be a life saver for huge graph.
    Thx again for you good work mate.
     
  11. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    It's been on the roadmap for a very long time, there is even an old proposal pull request on the GitHub page. I haven't gotten around to giving it an implementation yet though. Right now the easiest approach to simplify graphs is to implement sub graphs. Depends a lot on your design though.
     
  12. PeppersGamer

    PeppersGamer

    Joined:
    Jan 18, 2018
    Posts:
    17
    I am curious about the run time option and will explore it. I want to create a game for my son. He only wants to play with the plugs as he call them. The idea would be you connect nodes at run-time to spawn an elements such as a platforms, enemies, anything really, and give it a spacing, height offset whatever. He likes Mario maker so it would be cool for him to play with. I know that there are already coding games for kids but i think this would be a little different. I am thinking something like Archimatix but at runtime.
     
  13. fbmd

    fbmd

    Joined:
    Dec 4, 2016
    Posts:
    16
    Any idea when an official Odin integration is on the roadmap?
     
  14. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
  15. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Update! Odin Inspector support has now officially been merged into the main branch!
     
  16. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    RogDolos and zyzyx like this.
  17. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    I am pretty new to this, so please forgive if I ask the obvious...:
    a) is there a tool that helps reduce time needed to create prefabs for nodes (runtime nodes). I can reverse engineer how to do it quickly, but there are many scripts that need to be rehooked etc. to make even a simple node work runtime.
    b) how do I control execution when in editor mode - on what input events it re-evaluates? Can I pause/unpase/force evaluation?
    c) suppose I don't want my graph network to "do the job" on target gameobjects, but rather generate a recipe in a form let's say of a scriptable object. Where to start with that?
     
  18. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    xNode is not built with runtime graph editor in focus. there are other free node editor plugins that focus on this.
    I don't think anyone has made a proper "runtime xnode editor" tool.
    xNode does not come with any kind of flow. It will 'evaluate' when you ask it to (eg. call GetInputValue)
    I'm not sure what you mean with this question. xNode graphs always exist in ScriptableObjects
     
  19. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    @Siccity thank you very much. All clear. My main concern with evaluation was that when using editor nodes (regular nodes), I observed the entire graph is evaluated multiple times when I hover over node's output. I guess this is Unity related stuff. I am wondering how to make it evaluate on request only.

    About alternatives - I am looking strictly for a solution tailored for runtime graph editing. Do you by any chance know whether Node Editor Framework is simpler to setup for runtime mode?

    Best!
     
  20. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Hover tooltips get their information from calling GetValue on the hovered port, so if your GetValue triggers a full graph reevaluation, then yes, it will reveluate.

    An fix to this would be to have GetValue return a cached value, and only reevaluate when values change. This also will improve your performance a lot in the long run.
    If runtime editing is what you're after, you'll probably have an easier time using NEF, yeah.
     
  21. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    @Siccity I am much obliged for help!
     
  22. TeotiGraphix

    TeotiGraphix

    Joined:
    Jan 11, 2011
    Posts:
    145
    @Siccity This is an awesome project and I hope to contribute(github), I have a visualizer using the node graph, so hopefully can give some pull requests coming up.
     
    Siccity likes this.
  23. TeotiGraphix

    TeotiGraphix

    Joined:
    Jan 11, 2011
    Posts:
    145
    > I don't think anyone has made a proper "runtime xnode editor" tool.

    I want to work on this down the road, especially making it available in WebGL.
     
    giggioz and Siccity like this.
  24. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    Do you by any chance have some runtime UI wrapper for Xnode?
     
  25. TeotiGraphix

    TeotiGraphix

    Joined:
    Jan 11, 2011
    Posts:
    145
    > Do you by any chance have some runtime UI wrapper for Xnode?

    Yes but I am at the state where I am developing an app with it right now. That said, time is always the issue but basically an adapter for the xNode API into the graph rendering at runtime.

    So.. for safety, xNode is the compile time serializer, runtime deserializes and use that model, but could be any other model with an adapter to draw a graph. This is complicated, so I don't want to think I am not going to run into things trying to keep the abstraction.
     
    Siccity likes this.
  26. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
    @TeotiGraphix is there a way to intercept input events (like mouse wheel etc..) so I can override them with mines?
    The use case is for example a zoom (using mouse wheel) on an image contained inside a node. (and I don't want the graph to zoom as well)
    thx
     
    Last edited: Oct 17, 2019
  27. TeotiGraphix

    TeotiGraphix

    Joined:
    Jan 11, 2011
    Posts:
    145
    Off the top of my head, I don't know. The editor API is so crusty, I would actually have to try and figure this out myself to give you an answer, so I don't know at this time.
     
  28. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
    I had to modify NodeEditorGUI.cs code :(
    Maybe you could just add a property to enable/disable input like this?

    Code (CSharp):
    1.             if (!blockInput)
    2.                 Controls();
    3.  
     
  29. shadow-river

    shadow-river

    Joined:
    May 29, 2013
    Posts:
    63
    Hi, I was wondering how to go about creating a manager to paras through each node starting from a start node then going through each input-output till it reaches an end node.
    for instance I have a start node that leads to a string node, all nodes have a function named ONTrigger(), which will do a specific thing when triggered....In my graph I have the start node then 3 string nodes. I just need it to look through each node in sequence and then trigger the ONTrigger() function.

    if Someone could point me in the right direction, would be a huge help. Thanks in advance.
     
  30. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Check out the examples
     
  31. Yukken

    Yukken

    Joined:
    Jul 12, 2015
    Posts:
    93
    So I picked this up for making AI. I understand how to make node and graph classes. But how do you evaluate the graph? Is there no way other than making and calling a function on the graph class that loops through all the nodes in the graph, does a conditional check and evaluates them?

    Is there no way to specify a function that traverses the necessary nodes in the graph to return an output from the final node or do I need to write my own logic for that?

    What I want to do is the following:

    1. Have a blackboard of sorts for holding external variables. Like player position and stuff that will change in runtime. I can pass those in as parameters in the evaluation function of the graph class. But how do I feed those parameters to the nodes to produce outputs? And these parameters would likely be different for each enemy instance.

    2. Evaluate only the necessary nodes to reach a certain output node. I could loop through the entire graph but the problem with that is the nodes might need to be evaluated in a certain order. I could run something like DFS to find that path I guess but I'd still need to cache it somehow.

    Would Node Editor Framework be better in this case since it supports traversals(I haven't looked into it).
     
    Last edited: Nov 21, 2019
  32. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    There are a million different ways to traverse a graph, all dependant on your needs. For this reason, xNode does not come with built-in traversal. A common way of doing it is start by looping through your node list and find your start (or end) node, and trigger (or request output from) that. Your trigger method should evaluate your node as well as trigger the next nodes in the chain.

    I recommend looking at the examples.
     
  33. Yukken

    Yukken

    Joined:
    Jul 12, 2015
    Posts:
    93
    So I'll need to traverse the list manually. I have some other questions:

    1. Any way to mark a node so that I can know if it's a specific node I want when I'm traversing the list (Other than differentiating through typecasting/putting a flag field in the node class)?

    2. Can I safely keep refs to a certain node after I've found it?

    3. Is it possible find which nodes a node's input port is connected to?

    4. When I evaluate a node do I automatically evaluate the ones the node's input ports are connected to beforehand? Or do I need to evaluate those nodes first somehow.
     
  34. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    No. A bool flag is fine.
    Sure. Just make sure to cache values in non serialized fields, as ScriptableObjects are not cleared in editor.
    Yes. Completely the same approach as for outputs.
    GetPort("myInput").GetConnection
    You can evaluate just however you want. xNode does not interfere with your evaluation process
     
  35. Yukken

    Yukken

    Joined:
    Jul 12, 2015
    Posts:
    93
    @Siccity Thanks for the clarifications. I swear this'll be my last question.

    My question is less about xNode specifically and more about scriptable objects. What's the best way to handle instance variables? Say I want to use the same AI graph I made for different enemy instances. Since all enemies have the same Scriptable object they'll all be modifying the same variable. Which is not good if I want something like a cooldown timer.

    The simplest solution would be to keep a dictionary with enemy references as keys and field as values. Any thoughts?
     
  36. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Each AI can perform a graph.Copy() on start to create its own deep copy of the AI graph to run in. This way you avoid ever getting your graph altered from external sources too.
     
  37. sarah22

    sarah22

    Joined:
    Aug 6, 2017
    Posts:
    15
    Is there any way to make the node looks like the one in behavior designer? I'm planing to write an visual editor for my behavior tree but I couldn't find any node api like the one below.

     
  38. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    You can skin nodes freely and use angled connections, but vertical connections are not yet supported.
     
  39. ArnezH

    ArnezH

    Joined:
    Dec 10, 2017
    Posts:
    8
    Hey I would like to thank you for having this available it has really helped out a project that I've been working on I just have one question. Its how to make the objects for condition checking on the branch node. I cant really seem to find a clear example of what to do or what is needed if there's a way I will be forever grateful.
     
  40. szablac

    szablac

    Joined:
    Aug 25, 2017
    Posts:
    1
    Hi,

    I would like to know how can I connect an ingame (not a prefab) gameobject with the node as an input.
    Thank You in advance.
     
  41. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    Quick question, I have a simple test NodeGraph which has 4 nodes in it, from my game I get the NodeList from the NodeGraph object so I can run through the nodes and build a custom system from it. The count on the nodes is 5 though instead of 4 and if I just try and print the name of each node I get an exception when I try and access the 5th item, why does the nodes list hold 5 items when there are only 4 nodes in my graph?

    Another quick question are the nodes in any kind of order in the list or just the order they were added? Is there a way an API way to get the root object and run through the children or do I just use the Ports values and build it myself?
     
  42. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Nodes are ScriptableObjects. ScriptableObjects can't reference scene objects. You have to use an ID system to get gameobject references.

    This can happen if a script was deleted or renamed outside Unity, or something else went wrong and Unity can no longer find the class associated with the node. The node becomes an invalid scriptableobject and unfortunately there is no way to clean up invalid SO sub-assets as they can't be referenced. I did add some asset postprocessing to try and fight this issue, but it only works when removing or adding scripts inside the editor.

    The order is just the order they were added. A one-directional order of nodes wouldn't be of much help anyways as graphs can have several roots, branching, loops, etc
     
  43. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    If I put a Range() attribute on a value in my node then its very hard to change the value, is there a reason for that, ie if I have an int value and have Range(0, 3) attribute on it next to impossible to get it to change value on the graph.
     
  44. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Without testing it myself, my guess is it has something to do with zoom levels. Zooming with IMGUI sometimes makes odd behaviour with built-in unity drawers. If your minimum zoom is set to 1 and you zoom all the way in, it should behave normally.
     
  45. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    Is there a way to have it show the connections going into an input so I can clear just the one I want, at the moment if I have some complex graph with a lot of connections going in out of nodes if I need to reroute one I have to clear all the connections and wire them all up again. It would be nice if I could right click the line and just clear that connection, or is there some functionality I am missing?
     
  46. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    Also another issue when I add a new node to the graph that seems to become the root node for everything and all the pre existing nodes are children of it in the project view. Shouldnt the graph remain as the root with all the nodes of it?
     
  47. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,206
    Handled that in my system by allowing to save the graph to the scene, if the ScriptableObjects ARE scene-only objects, they can properly reference scene objects. That is not optimal if you plan to use the graph in multiple scenes with different objects each though. Then only an ID system is going to help.
     
    Siccity likes this.
  48. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    There are some issues with the newer versions of Unity. They changed their asset database to a broken one. An effort to prevent this mixup mas been implemented not too long ago. Are you using the newest version from the master branch?
     
  49. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Thanks for the tip! Will look further into this tomorrow.
     
  50. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Not right now, unfortunately. However, you can 'cycle' through the input connections by clicking the port. Every time you press and hold, the selected connection is highlighted, just keep clicking till the right connection is highlighted.