Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

xNode - A general purpose node editor

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

  1. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,685
    Mmm not seeing anything change when I click the port, I assume press and hold is left click and hold on the port circle gizmo? No colors change or anything is displayed to show I am cycling through the connections and the the connection lines are not changing in any way, am I doing something wrong?
     
  2. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Is this not what's happening? Perhaps your noodles are white and it's just unnoticeable? Are you on the newest version from the master branch?
     

    Attached Files:

  3. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Thanks! That was super easy to implement and xNode now supports scene graphs with scene references :)
     
  4. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,685
    I am using the version on the asset store, guess thats out of date? Will it break my graphs updating to the latest version from github?
    Will the latest version also fix the last added node being the root node and not the graph object?
    Does the latesest build also fix the issue where if you set the GUI.backgroundcolor in a node editor script it seems to be applied randomly to other nodes and sometimes ignored.
     
    Last edited: Apr 3, 2020
  5. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    The asset store version and the github release versions are updated rarely, and ). I always recommend using the master branch directly, ideally as git clone or submodule. Your graphs shouldn't break when updating. Yes this should fix the root asset problem. For the GUI.backgroundcolor you should revert the color back to its original state after your gui draw calls.
     
  6. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,685
    Thanks for the help, updated and got the connection highlighting working etc. Only problem I have now is when I set GUI.color or GUI.backgroundcolor in the node OnBodyGUI method it doesnt change the grey at all just changes the backgrounds to say float values etc. How do I change the node dialog background colors?

    Would it possible to add to the preferences window a custom color for each node type like it does for the 'Types' section

    No worries I found the NodeTint attribute.
     
    Last edited: Apr 3, 2020
  7. MasonWheeler

    MasonWheeler

    Joined:
    Apr 2, 2016
    Posts:
    210
    I get that the whole thing is ScriptableObject-based and you can't input values from the scene into the nodes, but the major node system in Unity, Shader Graph, has a good way around this. There's a "tray" off to the side that holds a bunch of variable references that can be turned into input nodes, and those variables end up as fields on the shader that can be input from the scene.

    Is there any way to set up something similar for xNode, perhaps in conjunction with something like the SceneGraph<T> class?
     
  8. isbasher

    isbasher

    Joined:
    Mar 19, 2014
    Posts:
    6
    I have a made an ability system using this. its working fine. but i've noticed that when you duplicate the asset the main asset is not the graph but some of the nodes that has inside. the same happen when you rename it. is there a fix for this? anyone had the same problem?
     
  9. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Yes this was fixed a few months ago. You just need to use the newest version from master branch :)
     
  10. Epsilon_Delta

    Epsilon_Delta

    Joined:
    Mar 14, 2018
    Posts:
    206
    Hello Siccity,

    first of all great work with the xNode!
    I was looking for something like this to use as a mindmap/graph like data structure for game design purposes. My question is: is it possible to have input/output connections without any variable? I am just interested in a parent/child relationships, no need for any values passing around.
     
  11. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    The direct way of creating ports is by adding an attribute to a field. This naturally means adding a variable. You can, however, use dynamic ports, which can be added or removed at any time and are not bound to any variable. Using a variable is much easier though, usually people just use a placeholder class and leave it at null.
     
    Epsilon_Delta likes this.
  12. odan-travis

    odan-travis

    Joined:
    Apr 12, 2019
    Posts:
    10
    The graph editor closes the active graph on play. Is this a bug or fundamentally something you want to prevent? I notice I can just open the same graph again, but that's annoying. If the graph is an asset (as opposed to a scene graph) it stays open, but of course those nodes shown aren't the actual nodes that I later instantiate. Is there maybe a way to simply show the instantiated copy in the (already opened) graph editor when play starts and turn it back to the asset when play ends via code?

    I would like to add debug features to my FSM implementation using xNode (like glowing outline around the running node, animating state transitions etc.) and need it opened in play mode for that purpose.

    (also if you change stuff during play mode, it will break the serialization / deserialization, at least with scene-only graphs. Errors when exiting play mode and opening the graph. I would expect that for scene-only graphs, the state is reset to what it was before play mode.)
     
    Last edited: Jun 10, 2020
  13. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    This is a bug. I have added an issue on github here. I'm guessing this is because pressing play instantiates a new graph, as opposed to using the same asset if you weren't using SceneGraph.

    I can't make it produce any errors on my end. Perhaps this has to do with your implementation?
     
  14. odan-travis

    odan-travis

    Joined:
    Apr 12, 2019
    Posts:
    10
    Yes,sorry, I think that was on my end. Didn't have separate source files for separate nodes, so Unity serializer broke
     
  15. mike1997

    mike1997

    Joined:
    Jul 1, 2016
    Posts:
    25
    This might be a dumb question, but is it possible to use xNode to make a standalone app, i want to make a dialogue system that you can run outside of unity editor.

    If its possible could you give me some direction on how to achieve this
     
  16. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    xNode is not built to be run outside the editor. There is an example branch on github that gets around this, but its not very effective.
     
  17. mike1997

    mike1997

    Joined:
    Jul 1, 2016
    Posts:
    25
    Thx for the prompt reply, i will stick to unity editor then.
     
  18. RonaldMeijers

    RonaldMeijers

    Joined:
    Nov 28, 2019
    Posts:
    3
    Nice, the runtime nodes are exactly what I was looking for.
    Question, is it possible to save a graph I create in runtime to a new scriptable object? eg. build and save node graphs in runtime / UGUI.
     
  19. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Unity does not support serializing ScriptableObjects at runtime.
     
  20. RonaldMeijers

    RonaldMeijers

    Joined:
    Nov 28, 2019
    Posts:
    3
    I see, but I could theoretically write the data to an already existing ScriptableObject, couldn't I?
     
  21. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Yeah, it's entirely possible, it just requires some extra setup.
     
  22. RonaldMeijers

    RonaldMeijers

    Joined:
    Nov 28, 2019
    Posts:
    3
    Thanks, I'm going to look into that.
     
  23. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,685
    I was using Xnode today and lost a couple of hours because I was editing one graph thinking it was another one as there is no way to tell which graph you are currently editing if you happen to select another object in the project etc. So I made quick change to the NodeEditorGUI OnGUI method to display the name of the graph being edited. Just in case anyone else has the same issue the quick change is below.
    Code (CSharp):
    1.       protected virtual void OnGUI() {
    2.             Event e = Event.current;
    3.             Matrix4x4 m = GUI.matrix;
    4.             if (graph == null) return;
    5.             ValidateGraphEditor();
    6.             Controls();
    7.  
    8.             DrawGrid(position, zoom, panOffset);
    9.             DrawConnections();
    10.             DrawDraggedConnection();
    11.             DrawNodes();
    12.             DrawSelectionBox();
    13.             DrawTooltip();
    14.             graphEditor.OnGUI();
    15.  
    16.             // Run and reset onLateGUI
    17.             if (onLateGUI != null) {
    18.                 onLateGUI();
    19.                 onLateGUI = null;
    20.             }
    21.  
    22.             if ( NodeEditorWindow.current )
    23.             {
    24.                 GUIStyle myStyle = new GUIStyle();
    25.                 myStyle.fontSize = 40;
    26.                 myStyle.normal.textColor = Color.white;
    27.                 GUILayout.Label(NodeEditorWindow.current.graph.name, myStyle);
    28.             }
    29.  
    30.             GUI.matrix = m;
    31.         }
     
  24. KHY_

    KHY_

    Joined:
    Aug 9, 2018
    Posts:
    1
    Hi, extremely useful tool, thanks!

    I'm wondering if anyone else has an issue with the selection box. There seems to be a weird offset in the drag starting point that's higher than where I start mouse dragging. The erroneous offset changes based on zoom as well.

    Edit: Turns out I had an old version, updated from github and everything's working fine. My bad!
     
    Last edited: Jul 31, 2020
  25. el_trex

    el_trex

    Joined:
    Apr 13, 2016
    Posts:
    22
    Hi. First thanks for your work here !
    I plan to try using your node based graph backbone to make an interactive, at run time, node graph for user (so not only in editor for devs).

    I saw some work have been made in this direction already (dynamic ports and the run time math example).
    But I'm wondering, adding a dynamic output port at runtime, how can I write / select the logic behind this output computation dynamically ?
    From what I understand, all your nodes logic (in the example) are statically coded in their C# script file in the getValue(port) overrided method, right ?

    I could use an embedded script engine (python or lua for example) to achieve this dynamically, but isn't it a too complicated solution ? Have you another more simple idea in mind when you was going on this "runtime" approch of xNode ?

    Thx.
     
  26. theguywiththelemon

    theguywiththelemon

    Joined:
    Dec 10, 2017
    Posts:
    2
    Thanks man! This is so useful!
     
  27. el_trex

    el_trex

    Joined:
    Apr 13, 2016
    Posts:
    22
    Can I Up my own post, as I still wonder how I need to best implement runtime logic of runtime node ?
     
  28. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,206
    Not exactly sure if you need a runtime UI for the user or not, but my Node Editor Framework (link below) supports that (it's a lot more runtime focussed, e.g. you can save graphs at runtime, and it keeps the tight Logic/GUI coupling of unity, like it or not). But since you're already over a month in development I assume that won't help you anymore...
     
  29. el_trex

    el_trex

    Joined:
    Apr 13, 2016
    Posts:
    22
    Thanks for the answer ! I'll check it out (actually I'm doing it right now ;) ).
    I'm not actively working on it, it is a side project. So yah it is a month from now but still in early stage.
    My goal is kind of offering a generic node editor for user to use them as they want, kinda like xNode but for user (so outside Unity Editor).
    I've come across this asset too who look interesting at first glance, I'll check on it too (Logic Forge).

    Will certainly understand yours soon enough, but maybe you can tell me right now : is it possible with your framework to somehow "link" or "load" a "logic" (e.g. script code for the node behavior, with input / output ) for a node at runtime (outside of Unity Editor) ? And modifying the script dynamically (maybe not in the resulting app for now, but at least the possibility to do it ? If ever I'll implement a custor script editor maybe) ?

    Thank will continue reading your framework ;)
     
  30. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,206
    In the typical sense that would require a script recompile, so unless you do some fancy custom scripting language that'd be pretty hard.
    If the user would use the UnityEditor to repackage their custom code into a .unitypackage, then yes, you could - the nodes can be refetched at any point at runtime to include the newly loaded ones. However that seems to be defeating the purpose of the node editor.

    So the best option might be to provide a programming-like interface using nodes as building blocks - similar to what all the visual programming node editors do.
    Maybe of interest to you, in the past I looked into dynamically calling arbitrary functions and working with arbitrary types some years ago - pretty sure it's broken by now, but have a look at this branch - especially Action Node, which basically allows you to call any function available in the code space, and provide appropriate inputs, even at runtime. If you replace UnityFunc there with SerializableAction (my replacement for my earlier implementation) you might be able to get it to work again (and perhaps directly serializable to XML, so your users could create graphs calling functions and combining it with existing nodes, and be able to save that for the next session to XML - that is not at all trivial).
    But this will get complex super quickly, and I don't want to fill this thread with unrelated stuff.
    Good luck!
     
  31. HuginnRaven

    HuginnRaven

    Joined:
    Dec 20, 2015
    Posts:
    33
    Here's what I'm trying to do and what I would love to get some help with.
    I'm trying to create a Fallout type of dialogue interface. I figured it would be the easiest way to get my vision onto the screen. Simple enough, right? Well.

    I want to add and remove answers based on the information the player has about the character they're talking to, but I don't want to permanently alter the files. Is there a way I can do this?

    Any help would be appreciated.
     
  32. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,009
    Hello I got problem understanding what is the licensing of this product.
    It is a paid product on asset store but at the same time it can be downloaded from git hub ?
    Is free downloading allowed only for testing purposes ?
     
  33. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    In the description on the asset store it says it's free. You can read the license here MIT License
     
    koirat likes this.
  34. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,009
    Are there any predefined nodes, like math etc ?
     
  35. MasonWheeler

    MasonWheeler

    Joined:
    Apr 2, 2016
    Posts:
    210
    None. xNode doesn't come with any built-in nodes; you have to set them up yourself.
     
  36. Deleted User

    Deleted User

    Guest

    Hi,
    Firstly, thank you a lot for the XNode! Is it possible to make text area much bigger? I'm trying to make quests system.

    upload_2021-2-6_20-42-35.png


    My code is very simple:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using XNode;
    5.  
    6. public class Base1 : Node {
    7.  
    8.     // Use this for initialization
    9.     protected override void Init() {
    10.         base.Init();
    11.      
    12.     }
    13.  
    14.     [Input] public float a;
    15.     public string x;
    16.     public string y;
    17.     [TextArea] public List<string> Texts;
    18.     //[TextArea] public string text;
    19.  
    20.     [Output] public float b;
    21.     [TextArea]  [Output(dynamicPortList = true)] public List<string> Answers2;
    22.  
    23.     private static GUIStyle editorLabelStyle;
    24.  
    25.  
    26.  
    27.     public override object GetValue(NodePort port)
    28.     {
    29.         if (port.fieldName == "b") return GetInputValue<float>("a", a);
    30.         else return null;
    31.     }
    32.  
    33.  
    34. }
    And my DialogueNodeGraph is clean:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using XNode;
    5.  
    6. [CreateAssetMenu]
    7. public class DialogueNodeGraph : NodeGraph {
    8.  
    9. }

    Thank you.
     
  37. hjohnsen

    hjohnsen

    Joined:
    Feb 4, 2018
    Posts:
    67
  38. Deleted User

    Deleted User

    Guest


    Thank you a lot for a reply. You helped a lot. You gave me Width. But I also found the Height which is in TextArea. Just add it like this [TextArea(8, 500)]. Here is my updated code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using XNode;
    5.  
    6. [NodeWidth(400)]
    7. public class Base1 : Node {
    8.  
    9.     // Use this for initialization
    10.     protected override void Init() {
    11.         base.Init();
    12.        
    13.     }
    14.  
    15.     [Input] public float a;
    16.     public string x;
    17.     public string y;
    18.     [TextArea(8, 500)] public List<string> Texts;
    19.     //[TextArea] public string text;
    20.  
    21.     [Output] public float b;
    22.     [TextArea(8, 500)]  [Output(dynamicPortList = true)] public List<string> Answers2;
    23.    
    24.  
    25.     private static GUIStyle editorLabelStyle;
    26.  
    27.  
    28.  
    29.     public override object GetValue(NodePort port)
    30.     {
    31.         if (port.fieldName == "b") return GetInputValue<float>("a", a);
    32.         else return null;
    33.     }
    34.  
    35.  
    36. }
    upload_2021-2-8_22-12-17.png
     
  39. DanielSnd

    DanielSnd

    Joined:
    Sep 4, 2013
    Posts:
    382
    I'm having some trouble with some nodes not being able to have their input/output ports pulled out randomly. :/ anyone ran into that issue before? not sure what to do about it.

    Tried joining the discord but the discord invite seems to be broken
     
  40. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    I haven't heard about that issue. The discord is https://discord.com/invite/qgPrHv4
     
  41. DanielSnd

    DanielSnd

    Joined:
    Sep 4, 2013
    Posts:
    382
    This is what happens when I go to that invite, I looked it up it says that the invite could be invalid, I could be at my server limit or I have been banned from that discord, but since I've never been to that discord before and I'm not at my server limit I'm assuming the invite is invalid :(

    upload_2021-2-22_15-37-36.png
     
  42. Mrmisklanius

    Mrmisklanius

    Joined:
    Dec 11, 2019
    Posts:
    15
    So I'm trying to make a dialogue system with this asset, and I have the nodes all set to test it out. But I can't figure out the best way to get the nodes to talk to my dialogue UI elements. I tried joining the discord but it didn't work for me either.

    Ideally what'll happen is it prints whatever is in the string fields to the respective UI elements. I'd like it to happen kinda dynamically. Mostly because I want it as automatic as possible. But at this point any tips would be super helpful. Maybe I overlooked something in the Wiki on it. I'm also wondering how selecting things would transition the dialogue tree to the next step. I tried the dialogue specific asset but when it imported it gave me errors that pretty much broke the asset.

    I'd love to get this figured out asap so I can use this asset for other things like skills and such.
     
  43. Mrmisklanius

    Mrmisklanius

    Joined:
    Dec 11, 2019
    Posts:
    15
    I JUST found that there's an FAQ answering what I need, I'll leave the question for future googler's to find and use. I'll give it some more testing and try to create a solution to the UI mess. The ID lookup system is a good idea and something I intended to Implement myself later down the line. Looks like I get to do that first lol. I'll post my work in the appropriate spot if I get a decent solution going.
     
  44. Mrmisklanius

    Mrmisklanius

    Joined:
    Dec 11, 2019
    Posts:
    15
    So I got my dialogue UI to show the first node dialogue + answers using:
    Code (CSharp):
    1. { get => ; set => ; }
    Then I converted that to .text and applied it to my UI text. Now I'm trying to figure out how to get the node to go to the proper next node through UI and in code. It's tricky as the wiki doesn't seem to give much examples of how to go about it. I'm using GetValue and such, I just don't know how to test it without the UI compatibility.

    I'm also trying to figure out how to update my current node in the node graph editor to the proper current node.
     
  45. MrRiktor

    MrRiktor

    Joined:
    Mar 14, 2021
    Posts:
    1
    So i've created a simple graph and simple node but when I Create -> SimpleGraph It creates the scriptable object but I am unable to add my simple node to the node list. I am using Unity 2020.2.4f1 and the latest version from the github.

    The XNode graph window is also blank at this point. I tried dragging the node script into the window and into the node list but nothing changes.
     
  46. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    500
    Question. Dragging game object to a node property.

    How would i accomplish something like that ?

    Either showing the object name inside it or showing the instanceID of the game object.

    Another approach would be to click a little target button next to the property box then click on the scene object and display the object or instance ID

    Some help on this would be appreciated?

    Any example code
     
  47. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    ScriptableObjects cannot reference objects inside a scene, unless that ScriptableObject exists inside that scene. To do this, use Scene Graphs instead. Alternatively you can implement your own ID system for referencing objects inside your scene.
     
  48. Tyndareus

    Tyndareus

    Joined:
    Aug 31, 2018
    Posts:
    37
    I haven't read through every post, might save that for later...

    But basically I need to do an expression tree.
    Consider a list of tasks, I'd believe doing something simple like a class that just holds the trifecta; ID, Name, Description would be fine (cutting out the displaying of the task, what happens when its done etc). Thats fine for one system, but now there may also be another system using the same type of outcome but the approach or condition is different, then there may be multiple of these systems etc.
    So I thought a little differently, what if there was a graph you could plot, and then execute on some event (in Unity maybe an object is clicked) so Script with graph reference -> Graph.Execute(), return node? not sure how the output is handled in a graph but basically another script or a UnityAction needs to continue after the graph basically completes the approach/condition.
    It should mostly be bool checking but obviously it could be some flag in script B or a counter in script C.

    From all that I found xNode again, but from what I remember xNode was all self contained functionality. Or could it have script nodes? I haven't delved into it properly, the output is one of the bigger questions.

    I also had a very quick look at the SerializedCallback package you have, the usage seems to be different from the readme, but may also have been on the same path of what I am looking for.

    tl;dr questions
    1. How would I use xNode to create a graph reference that is executed on some external trigger.
    2. Are outputs in xNode able to target a script function or raise an event in itself that would say "end of graph"? (preferably script function but I could use events to bounce off)
     
  49. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    1. You create graph references by first creating your graph and node scripts, then instantiating it in your assets folder the same way you would do with a ScriptableObject, then reference it with something like
    public MyGraph myGraph;
    . You can also call Copy() on an existing reference to create a new one.
    2. Outputs can only target inputs. But that input could belong to a node which fires whichever functionality you put in it.
     
  50. hanbekov

    hanbekov

    Joined:
    Apr 1, 2017
    Posts:
    8
    Hello Siccity, thanks for your Xnode work!

    some questions:

    1) How to get NodeEditor from Node? My need to get the width inside node function (calling GetWidth() from NodeEditor).

    2) How to get a height of node ? (too inside node function)

    3) How to link two node, by programm code? I try code like this:

    Code (CSharp):
    1. NodePort inputPort = null;
    2.             foreach (XNode.NodePort input in graph.nodes[2].Inputs)
    3.             {
    4.                 inputPort = input; break;
    5.             }
    6.        
    7.             XNode.NodePort draggedOutput=null;
    8.             foreach (XNode.NodePort output in graph.nodes[1].Outputs)
    9.             {
    10.                   draggedOutput = output; break;
    11.             }
    12.             if (inputPort != null && draggedOutput.CanConnectTo(inputPort))
    13.                  draggedOutput.Connect(inputPort);        
    14.             XNodeEditor.NodeEditorWindow.RepaintAll();
    15.             if (XNodeEditor.NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
    inputPort and draggedOutput is not null, draggedOutput.Connect(inputPort) executing, but connection not visible.

    4) How to expand all element array (list) in node, by programm code?
     
    Last edited: Oct 6, 2021