Search Unity

xNode - A general purpose node editor

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

  1. Rispat-Momit

    Rispat-Momit

    Joined:
    Feb 14, 2013
    Posts:
    266
    Hi there again! :)

    Is there any way I can add GameObjects from the scene to the graph or add functions such as instantiate?

    best,

    Rispat
     
  2. Eviral

    Eviral

    Joined:
    Mar 20, 2013
    Posts:
    35
    Hello,
    Great work !

    I would like to open the .asset file containing the instance of my xnode graph from a custom button in a custom inspector instead of by double clicking on the .asset file.

    How can i do that ?
    I can't find some code to do that...

    Do you know how to do that, please ?

    Thx

    Eviral
     
  3. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    There is no tutorial but there is a handy wiki that answers a lot of questions :D
    https://github.com/Siccity/xNode/wiki
     
    Rispat-Momit likes this.
  4. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Here's the code that opens the graph in xNode.
    Hopefully you can learn from it what you need :)

    Code (CSharp):
    1. [OnOpenAsset(0)]
    2. public static bool OnOpen(int instanceID, int line) {
    3.     XNode.NodeGraph nodeGraph = EditorUtility.InstanceIDToObject(instanceID) as XNode.NodeGraph;
    4.     if (nodeGraph != null) {
    5.         NodeEditorWindow w = GetWindow(typeof(NodeEditorWindow), false, "xNode", true) as NodeEditorWindow;
    6.         w.wantsMouseMove = true;
    7.         w.graph = nodeGraph;
    8.         return true;
    9.     }
    10.     return false;
    11. }
     
  5. Rispat-Momit

    Rispat-Momit

    Joined:
    Feb 14, 2013
    Posts:
    266
    Thank you Siccity,

    It is kinda hard to understand but I will give it a try. I have actually no idea of how it can actually work with anything except for calculating numbers. If I even manage to figure out how to use it for creating any kind of function I would love to make some standard Nodes that can help everyone use it with ease.
     
  6. Eviral

    Eviral

    Joined:
    Mar 20, 2013
    Posts:
    35
    Thanks a lot ! It works like a charm !
     
  7. BuzzardMercure

    BuzzardMercure

    Joined:
    Mar 11, 2015
    Posts:
    5
    Hey @Siccity !

    First off, xNode is absolutely wonderful. Basically exactly what I needed from a node framework. Clean and direct without any feature bloat that tends to complicate other comparable systems. Thank you for both creating and making it freely available (though I'll be buying it as soon as I can to express my appreciation).

    My main question here is about instance port lists. My goal is to dynamically fill an instance port list with outputs, but there isn't a clear example of how to use them and AddInstanceOutput is logging that the ports already exist. I've been banging my head against it all day, and the documentation doesn't provide a clear example of how to achieve this.

    Got any tips for me?
     
  8. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Glad you like it :)

    InstancePortLists are a pretty new feature and are pretty complex internally to be as flexible as possible. This means there might be some still to be weeded out. I recently wrote a bit of documentation here.
    If you encounter any bugs please report them to the issues page.

    If you take the manual AddInstanceOutput path, be wary that you'll need to draw your added instanceports yourself through a custom node editor. You can enumerate through them with
    node.InstancePorts
    and draw them with
    NodeEditorGUILayout.PortField
    They aren't displayed automatically yet, and that might be the answer to the issue you're having, that the port already exists in the node but isn't drawn. You can find cached port data if you select a node and look in the inspector to see for yourself.
     
  9. BuzzardMercure

    BuzzardMercure

    Joined:
    Mar 11, 2015
    Posts:
    5
    @Siccity thanks for the response!

    I'm able to add the new ports as individual ports, but I can't add them to the list. Here's some example code to illustrate:

    The node editor:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using XNodeEditor;
    5. using XNode;
    6.  
    7. [CustomNodeEditor(typeof(DialogueNode))]
    8. public class DialogueNodeEditor : NodeEditor
    9. {
    10.     public override void OnBodyGUI()
    11.     {
    12.         DialogueNode currentTarget = target as DialogueNode;
    13.  
    14.         NodeEditorGUILayout.PortField(target.GetInputPort("inbound"), GUILayout.Width(100));
    15.         NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("text"));
    16.         NodeEditorGUILayout.InstancePortList("transitions", typeof(DialogueNode.Transition), serializedObject, NodePort.IO.Output);
    17.  
    18.         if (GUILayout.Button("Build Outputs"))
    19.         {
    20.             currentTarget.ParseText();
    21.            
    22.         }
    23.  
    24.        
    25.     }
    26.  
    27.     public override int GetWidth()
    28.     {
    29.         return 300;
    30.     }
    31.  
    32. }
    The node itself:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using XNode;
    5. using IFTool;
    6.  
    7. public class DialogueNode : BaseDialogueNode {
    8.  
    9.     [Input] public Transition inbound;
    10.  
    11.     [TextArea(3, 15)] public string text;
    12.     private string processedDialogue;
    13.    
    14.     [Output(instancePortList = true)] public List<Transition> transitions = new List<Transition>();
    15.    
    16.     // Use this for initialization
    17.     protected override void Init() {
    18.         base.Init();
    19.        
    20.     }
    21.  
    22.     // Return the correct value of an output port when requested
    23.     public override object GetValue(NodePort port) {
    24.  
    25.  
    26.         return null; // Replace this
    27.     }
    28.  
    29.     public void ParseText()
    30.     {
    31.         foreach(string extractedLabel in IFParser.ParseByContainerTokens(text, "[", "]"))
    32.         {
    33.             AddInstanceOutput(typeof(Transition), ConnectionType.Override, "transitions");
    34.            
    35.            
    36.         }
    37.     }
    38.  
    39.  
    40. }
    I can pass in the extracted label from the parsing operation and the nodes are added fine, but not to the transitions list (transitions are defined in the dialog base class as an empty class with a string field for a label).
     
  10. Dizy

    Dizy

    Joined:
    Aug 22, 2015
    Posts:
    13
    Hi Siccity, i just discover your awesome and friendly node editor, greate work !

    I create a simple Utility Based AI and will provide some feedback on my work when i'm done.

    It seems thats the "Preferences" dont work with the news Unity windows settings system, are you planning to fix that ?

    type.GetMethod("ShowPreferencesWindow"... ) based on UnityEditor.PreferencesWindow type in assembly UnityEditor.EditorWindow seems to throw an error.
     
  11. BuzzardMercure

    BuzzardMercure

    Joined:
    Mar 11, 2015
    Posts:
    5
    @Siccity I actually solved my problem. I made the assumption that I would need to add the port manually instead of just adding the type I needed to the list. I think I was conflating the purpose of AddInstancePort and creating an instance port list and now I'm smacking my forehead a bit.

    Thanks again for the help!
     
  12. Dizy

    Dizy

    Joined:
    Aug 22, 2015
    Posts:
    13
    Hi again, i'm done with a weight-based-random version, you can find the AI nodes and an example here : https://github.com/FBast/xNodeUtilityAI

    I'm working now on a dual utility reasoner, a much more powerful and complex version. I keep you in touch.
     
  13. Dizy

    Dizy

    Joined:
    Aug 22, 2015
    Posts:
    13
    Hi again, is there any way to display an inputNode on the right side instead of left ?

    It's more convenient sometimes.
     
  14. borr

    borr

    Joined:
    Jan 22, 2014
    Posts:
    10
    1.how do i save the current position of the user in the node tree? next time to start from this node
    2. can I create custom gui layout for node? I want to hide or show some items. Depending on conditions
     
    Last edited: Feb 8, 2019
  15. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Try the newest version from the Github repo. It has this issue fixed.

    No. You can perhaps hack it in with a custom node editor, but i did not include any standard functionality for this.

    1. Make a public field reference to the node.
    2. https://github.com/Siccity/xNode/wiki/Node Editors
     
  16. borr

    borr

    Joined:
    Jan 22, 2014
    Posts:
    10
    thank you very much.
     
  17. Zillus

    Zillus

    Joined:
    May 31, 2017
    Posts:
    24
    EDIT: Nevermind. Of course, the second I post here it suddenly comes to me. I need to use OnCreateConnection to update the value. I had the code in GetValue, but of course it was never being used because that issues a return command.

    I think this looks great and I was following the basics until I hit a wall on something. I am sure the answer is very simple but I just cannot work it out: how do I capture the value of an incoming port and store it in a new variable?

    If someone could show me a simple node script that does the following I would be super grateful:
    - Receives a value to an input port from another node (let's call this incomingValue).
    - Creates a new float variable( let's call this newFloat).
    - Sets newFloat = incomingValue.

    I feel like it's so completely basic but I've been trying various things for an age now and I just can't get it. I can use the code from the sample SimpleNode.cs to receive a value at an input node and pass it to an output node (and I can see it is working in the graph from the tooltip), but putting it into a normal variable is beyond me :/

    Thanks.
     
  18. Zillus

    Zillus

    Joined:
    May 31, 2017
    Posts:
    24
    EDIT: The guys on Discord helped. The solution is to use graph.nodes[n] as MyNode to get a specific node type. You can check for node type by comparing against typeof(MyNode).

    Ok, I have another question. I want to access the data I have created in an xNode graph from other scripts. I can grab the list of nodes from the graph scriptable object but because they are generic nodes as opposed to specific nodes I can't find a way to extract any of the stored data.

    Maybe this is more of a Scriptable Objects question rather than an xNode question, but I'd appreciate a tip in the right direction. As they don't have transforms they don't have children, so I can't loop through the graph's sub-components (though in the project browser they certainly look like children).

    I can grab the data no problem by getting it straight from each individual node's scriptable object, but it would be much tidier to be able to corral all of the nodes from their parent graph. Is that possible? I guess it must but I don't see it.

    Thanks!
     
    Last edited: Feb 10, 2019
  19. Carlotes247

    Carlotes247

    Joined:
    Jun 12, 2014
    Posts:
    9
    Hey! Great work with xNode @Siccity ! We are using it at Goldsmiths, University of London and we are quite happy with it :)

    I'm just raising an issue with Unity 2019 that I also commented in the Github.

    It seems that in Unity 2019 many things are different and the [PreferenceItem("Node Editor")] under NodeEditorReflection.cs throws an error because it's now deprecated. Unity apparently now uses [SettingsProvider], but the way it works is quite different.

    Currently just by changing one attribute with the other breaks the Preferences customisation menu.

    More info:
    https://docs.unity3d.com/ScriptReference/PreferenceItem.html
    https://docs.unity3d.com/2018.3/Documentation/ScriptReference/SettingsProvider.html
     
    Siccity likes this.
  20. Dizy

    Dizy

    Joined:
    Aug 22, 2015
    Posts:
    13
    I think you just encounter the same problem than me. As Siccity said :

    That fix is not available in the last release so i just downloaded the master branch and it seems to work nicely
     
    Siccity likes this.
  21. Carlotes247

    Carlotes247

    Joined:
    Jun 12, 2014
    Posts:
    9
    Thank you for answer @Dizy we were using the master version already (latest one), but I have been trying a few things and I have new comments.

    It seems that if I create an empty Unity 2019 project and then I copy-paste the scripts from xNode, I get the same errors that I mentioned before:

    upload_2019-2-13_12-27-34.png

    However, if I create an empty Unity 2017.3 project, copy-paste scripts from xNode, and then upgrade that project to Unity 2019 xNode seems to work. Maybe there is some sort of magic upgrade logic in the background?

    To be honest, it seems a bit weird since the same line of code that causes problems in my first approach is still there, with a green warning in Visual Studio but I can compile the project and the preferences window still appears and works.

    upload_2019-2-13_12-32-54.png

    Any thoughts?
     
  22. Dizy

    Dizy

    Joined:
    Aug 22, 2015
    Posts:
    13
    My bad, i misunderstood your problem. I'm using Unity 2018.3 then Rider dont bother me with that. It need some refactoring to use it with SettingsProvider on Unity 2019 i guess.
     
  23. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    Just to chime in and reiterate what many others have already said, that xNode is great work @Siccity.

    Been playing around with it for the last few days and having fun. Have a few questions and suggestions I want to post, but for now I just wanted to add to this thread that I've added a pull request with a simple 'quality of life' feature that allows double clicking on the Node header to automatically center it in the editor window.
     
    Siccity likes this.
  24. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    Contributing to xNode File Formatting and Styles
    Having made my first pull request and seen that despite my best efforts @Siccity still had to reformat some of it ( sorry ), i'm wondering what can be done about ensuring maximum compatibility?

    The problem from my end is I use a considerably different set up to that of the source, almost every aspect of layout, formatting and style is different. I tried my best to maintain the formatting/style even going as far as to have multiple repositories so that I could try and massage my changes to match the source formatting. Unfortunately Visual Studio only has settings per application and not per project and i'm just not willing to go in and change them all ( dozens of them ) by hand each time. I tried using an editorConfig, but that only contains a subset of the VS formatting options and actually ended up causing greater difference in the files! I tried something called ReBracer extension, but it is no longer supported by VS 2017 and there are some trust issues with using modified versions of it.

    In the end I had to go in and hand modify my code to match ( replacing tabs with spaces ) and even then it still had a number of differences that had to be fixed afterwards.

    So whats the solution? Any bright ideas? Perhaps I could use another editor ( e.g. sublime ) to modify the scripts before pushing them to github, but i'm concerned that it might again end up with some differences that make the effort almost worthless?

    Something i'm wondering about is whether accepting a pull request automatically causes a new commit? If it does then we get the situation I saw here which is a single pull request ended up with two commits, one for the pull, another for the formatting fixes that needed to be performed. If that can be avoided that would be nice as it would keep the repro clean from additional commits.
     
  25. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    A whole bunch of things ...

    Minimum Supported version.
    As the repro does not include a full Unity project I'm unsure what the minimum Unity version supported is/should be. Would be nice to have that information added to the read me. Currently i'm working with 5.6.6f2 as min since there was at least one conditional define in the code referencing Unity 5.5.x

    Bogus ContextMenu Popup - the Unity copy/paste popup menu.
    As noted in a previous post #107 in this thread earlier versions of Unity ( 5.6.6f2 to 2017.3.1f1, but not 2018.3.2f1) right-clicking to obtain the Node Header ContextMenu and selecting an option ( e.g. rename ) will also pop up the Unity copy/paste context menu. This can be fixed by adding e.use() after line 278, where it calls menu.Dropdown() in NodeEditorActions.cs.

    However I suspect this highlights a deeper problem, that being events need to be 'used' more consistently in the code after an action is performed. For example I would probably expect it to be added into every conditional in the event.mouseUp and elsewhere. Unfortunately it is not clear or obvious as to when to do this, further more its a bit messy as you are going to end up with many e.use(); lines dotted throughout the code. Not sure what the best approach to take here?

    Maybe NodeEditorActions could be refactored to make adding event.use more consistent and straightforward?

    In general i'd love to see NodeEditorActions .Controls() refactored to contain just the switch statement and have its cases call sub methods in the class. Its a personal thing but I find it much easier to parse the code when its split up like that. I could take a look at doing that, though the amount of code that would appear changed in a diff check would be large and take longer to validate from a pull request.

    NodeEditorActions: EventType.KeyDown
    First conditional statement does not require else statement for KeyCode.F.
    Why is RenameSelected() using different keys between Mac and PC?

    NodeEditorActions: EventType.ExecuteCommand
    Conditional statements here all needlessly perform e.type == EventType.ExecuteCommand checks since that is already done by the switch statement and so they can be removed.
    Unsure what the difference is between softdelete and delete or why you wouldn't want delete on windows to perform the same operation?
    Could using a switch case with fall through make this more readable?

    ContextMenu use breaks Keyboard controls.
    Whenever you use right-click to obtain a contextMenu Unity is setting EditorGUIUtility.editingTextField = true for some reason that I have yet to discover. This will then prevent any keyboard controls being caught in NodeEditorActions: EventType.KeyDown.

    Perhaps instead of checking for editingTextField we check keybaordControl as in theory it should be 0 if not editing a control? However working out why editingTextField becomes true would be good.

    Consecutive right clicks in editor window will cause it to pan.
    Right-clicking to get a context menu up on grid then right-clicking again elsewhere will pan the window. Doesn't happen in 5.6.6 but does in 2018.3.2. Probably fixable, but not worked out how/best method yet.

    Renaming/Editing Node Name
    If you start renaming a Node Header but then click on another Text entry control type on any node, will not cancel editing the header! So renaming variable remains set etc. Luckily hitting return whilst editing another field will 'finish renaming' however it suggests to me that this feature is not as robust as it should be.

    Wondering whether we can get the name displayed in the inspector for a selected node and be able to rename it there? This would be like how the animator works.

    ContextMenu:Reset will completely break the node/graph.
    Using the contextMenu in the inspector ( that cog thing ) and selecting 'Reset', will, not unexpectedly completely break the node. We can override the Reset method in the node.cs, but from a quick test it still loses references to its graph and maybe corrupts other data such as ports/connections etc. Not sure if there is a good solution other than 'don't do it' ;)

    There are a couple of others I noticed but I want to investigate further, such as InstancePorts creating a default referencing to the field ( e.g. List or Array) rather than contents of the field, or when deleting/changing fields marked as ports leaving old references to those fields.

    Anyway as i said previously xNode is a great framework, these are just a bunch of things that came up as I was playing around with it that can hopefully be addressed over time or by someone with greater knowledge of the code than I currently have.
     
  26. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    I use VSCode with the C# FixFormat extension. Default or near-default settings if I remember correctly. VSCode supports per-project settings.

    I have several options when accepting a new commit. I can merge, fast-forward merge, or squash and merge. I can also fetch your remote (which i did in this case) and apply more commits before merging. The best approach however is if you create a new branch for your pull request, so that the pull request doesn't come directly from your master. If you PR from a non-master branch, i can actually push directly to that branch, on your repo. That way we can have a back-and-forward thing before finally squashing it all and merging with a fast-forward. This approach is by far the cleanest (see https://github.com/Siccity/xNode/pull/43) and produces just a single commit directly on top of the branch.
     
    Noisecrime likes this.
  27. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    Cool, I've installed Visual Studio Code, good to have an excuse to try it, since I've wanted a nice dark theme for a while and Visual Studio's options are both limited and often incomplete. Be interesting to see how well it works as the default editor for Unity too.

    Been through the set up and added the FixFormatting extension, however the default set up is not exactly the same as you source. I tweaked a setting or two and *think* its the same, but will need to confirm. However it would probably be much simpler and more correct if you could add your settings to the wiki or something?

    As far as I can tell this should be relatively simple since VS Code only adds values that are changed to its settings and its all in plain text and tagged ( e.g. csharpfixformat. ), though possibly spread between a couple of files. Again AFIAK you should find all the relevant settings between either the global defaults settings.json ( meant to be at '%APPDATA%\Code\User\settings.json', but I found them at 'AppData\Roaming\Code\User', whilst per project settings are in the workspace file.

    I'll try out your merge suggestion next time, though again be nice if you could find the time to add that to the wiki or contributing to project page on github as a suggestion for contributors to follow.
     
    Siccity likes this.
  28. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    I'm actually interested in support all the way back to 5.3, as Unity deprecated WebPlugin after that version. I've added it to the readme under Key Features. I don't think there's much difference in 5.6 and 5.3 in terms of code compatability.

    I agree NodeEditorActions is a bit of a mess. I made it this way because when I started xNode I had just come from a similar project that had implemented a fancy input action system, with action subscriptions and whatnot. It was hard to work with coming from outside, and ultimately I had to extend it for a new feature and it led to me not wanting to deal with it. I made it this "raw" way so that i could be sure not to run into potential issues down the road.

    I'm not sure just moving the stuff around fixes the underlying problem though, but it's worth a try, to see if it gets any more manageable.

    The `else` seems to be unnecessary, yeah.
    Mac and PC have different standards. A Mac user would expect Enter to rename a file whereas a PC user would expect it from F2. It's really just to keep consistency with the OS.

    True! Probably remnants of old code.
    I don't remember why i explicitly left PC out of "Delete" but pressing the delete key on a PC returns SoftDelete whereas Mac returns "Delete"
    A switch case could probably work in this case.

    I feel like I've been trying all sorts of combinations of keyboardControl, editingTextField and various hotControl stuff. It's all a great mystery to me. I'd be interested in more insight.

    Unity version inconsistencies, my favorite! I haven't personally upgraded to 2018.3 yet (waiting for the new prefab system to mature a little first) so I don't run into these issues myself. You could add it on the Issues page.

    Renaming definitely feels wonky at the moment. I've considered a pop-up with an input field; it would be ugly but functional. Taking inspiration from Animator, however, is a great idea!

    Reset does what Reset does. It's crystal clear in intention, and I think messing with it will just cause frustration. However, the graph still has references to the nodes. We could add a check before drawing a node that sets the node.graph reference if it's not pointing to the right graph. Similar automatic "node fix-ups" are already in place. Shouldn't be too hard.

    Glad you took the time to look into all this! Seems like there's a lot of room for improvement.
     
  29. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    Really? Been using windows for 20+ years and never used F2 to rename anything, guess you learn something everyday. Personally those i'd argue these days its more important to be consistent across platforms where possible and that perhaps RETURN/ENTER should also be used on Windows?

    I may take a look at this then sometime, unless its something you explicitly want to deal with?

    Wouldn't we all ;)

    Ok, but i'll look into it a bit more see if I can work out why. I think cleaning up NodeEditorActions.cs will help in that regard.

    Yeah it feels like its just a case of finding the best way to approach this. I had a look at using onInspectorGUI to add access to the name for nodes, but it doesn't look possible as it is inherited. But perhaps i'm missing something. It could probably be achieved by using a separate name property in Node, but that feels untidy.
     
  30. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    I use it a lot :D
    While I agree consistency across platforms would be great, the smart heads at Microsoft and Apple split the waters and made conflicting standards. As a Windows user I'd always expect Enter to trigger/execute the selected elements. I'd be more inclined to use Enter if it proved itself to be a more popular choice, but it seems to only be the standard to apple machines, and even has its fair share of people disliking it. I think F2 is generally considered the rename button.

    I probably won't do it myself in the near future, so feel free to have a shot at it. You might already know this but I am very strict about which pull requests I merge in, so I might reject it. But I'd love to see, or discuss possible solutions in the Discord chat.

    The issue is really just how we're going to present it to the user. Right now I got a bunch of stuff happening in OnHeaderGUI taking care of the renaming, but since that method is virtual, all rename functionality will vanish as soon as the user overrides it to prefix all his node labels with "-Horse".
     
  31. Ash-Blue

    Ash-Blue

    Joined:
    Aug 18, 2013
    Posts:
    102
    Here is a snippet that will automatically generate unique IDs for all available nodes (future and pre-existing). This is rather important if you plant to save and restore data from your xNode graph.

    Code (CSharp):
    1.  
    2. public abstract class NodeId : XNode.Node {
    3.     public string id;
    4.  
    5.     protected override void Init () {
    6.         if (id == null) {
    7.             id = Guid.NewGuid().ToString();
    8.         } else {
    9.             var match = graph.nodes.Find(n => {
    10.                 if (n == this) return false;
    11.                 var skillNode = (NodeId)n;
    12.                 return skillNode != null && skillNode.id == id;
    13.             });
    14.          
    15.             if (match != null) {
    16.                 id = Guid.NewGuid().ToString();
    17.             }
    18.         }
    19.     }
    20. }
    21.  
     
    Siccity likes this.
  32. borr

    borr

    Joined:
    Jan 22, 2014
    Posts:
    10
    Can I select a node and scroll screen to it from the script code?
    it is right?
    Code (CSharp):
    1. Node node = target.nodes[0];
    2. NodeEditorWindow.current.SelectNode(node, false);
    3. NodeEditorWindow.current.panOffset = -node.position;
     
    Last edited: Apr 10, 2019
  33. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Yeah that's about it. You might want to include the node's dimensions to really center it and not just center to its upper left corner. Here's some code from NodeEditorAction.cs
    Code (csharp):
    1. Vector2 nodeDimension = nodeSizes.ContainsKey(hoveredNode) ? nodeSizes[hoveredNode] / 2 : Vector2.zero;
    2. panOffset = -hoveredNode.position - nodeDimension;
     
  34. borr

    borr

    Joined:
    Jan 22, 2014
    Posts:
    10
    Thank you very much.
    just a little edit:

    Code (CSharp):
    1. Vector2 nodeDimension = NodeEditorWindow.current.nodeSizes.ContainsKey(node) ?
    2.                                 NodeEditorWindow.current.nodeSizes[node] / 2 : Vector2.zero;
    3. Vector2 pos =  -(node.position + nodeDimension);//this is important
    4. NodeEditorWindow.current.panOffset = pos;
     
    Last edited: Apr 11, 2019
  35. superjayman

    superjayman

    Joined:
    May 31, 2013
    Posts:
    185
    Can I use xnode in my own plugins which I want to sell on the Asset-Store? Cheers..
     
  36. superjayman

    superjayman

    Joined:
    May 31, 2013
    Posts:
    185
    How can you do a Texture2D input to a node? and draw the texture preview within the same node?
     
  37. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Yes definitely. xNode is MIT licenced.

    As you would a normal public field, but add the [Input] attribute. For custom node editors, make a class that derives from NodeEditor and set it up almost like you would with a normal custom editor
     
  38. superjayman

    superjayman

    Joined:
    May 31, 2013
    Posts:
    185
    Cool!

    Brilliant Tool, still learning it.

    Is it possible to use another graph as a node? sort of graph within a graph? Will you have a feature where, we can select nodes and make an embedded graph. Thanks again.

    Also, how can I customize NodeEditor Preferences per graph. I noticed there is GetDefaultPreferences in NodeGraphEditor, but how can I use this, where is the best place to call it?
     
    Last edited: May 1, 2019
  39. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    You can implement a subgraph system quite easily. Simply have a node with a public graph field, an input and an output. Then, depending on your flow implementation, add in some logic on how data transitions in and out of that graph. I did something like that for a state machine and it didn't take much more than 12 lines of code.

    For the preferences you can create a graph editor with the [CustomGraphEditor] attribute with the editorPrefsKey set to something non-standard. That way your graph will save and load it's own preferences file. The GetDefaultPreferences is only called when a user doesn't have any preferences. The function is called and the result is saved on disk. This way the user can still edit the Prefs afterwards
     
  40. superjayman

    superjayman

    Joined:
    May 31, 2013
    Posts:
    185
    Hey that's a good idea for the subgraph!. thanks for the suggestion, will try.
     
  41. FreeFly90

    FreeFly90

    Joined:
    May 28, 2016
    Posts:
    177
    Hey there! I've been using xNode for a while, trying to build my own dialogue system for a game I'm working on, and I really like it! However, there are a couple of things that I haven't been able to achieve for some reason, and I was wondering if you could help me with that.

    1) I have an ID property on my graph, and I edit through a custom box. I now need all my nodes to have an ID that is partly derived from the graph id. However, the graph variable is still null during the node init call, and I can't have any post-init function called automatically in the editor. Is there any way to get a reference to the graph from the node during the init phase?

    2) I'm using custom node editors, but for some reason the textarea don't behave as expected. Whenever I type the text in the editor, it keeps flowing behind the available space on the first line. However, if I paste the text from somewhere else it behaves as expected. Any possible reason for that?
     
  42. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    Node bypassing, timed execution, result baking - is that possible with this so nice looking framework?
     
  43. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Are you using an old version of xNode? A fix for this was introduced last year
    https://github.com/Siccity/xNode/commit/a0eee5b9caabe641e507954959d4f87683e14c51
    Otherwise perhaps open up an issue on github about it.

    Sometimes Unitys property drawers don't play well with zoom. The only way to fix this is to rewrite the property drawer, as I've done with NodeEnum. A detailed description of the issue on github is probably the best way to go if you need it fixed.
     
  44. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Yeah definitely.
     
  45. FreeFly90

    FreeFly90

    Joined:
    May 28, 2016
    Posts:
    177
    Thanks for the answer! I downloaded the newest version a couple of weeks back to test the TextArea fix but I didn't think about checking the graph reference, I'll do some testing and get back to!:)
     
  46. CptKen

    CptKen

    Joined:
    May 30, 2017
    Posts:
    216
    Does it have support for nested layers?
     
  47. at1012

    at1012

    Joined:
    Mar 10, 2013
    Posts:
    6
    Hi Siccity, awesome asset! Thank you for your hard work. I did notice a bug when playing around with the Math Graph editor example in the latest release.

    In a new project, tested with Unity 2019.1.4, when attaching the export port of the "vector" node to an import port of a "Math" node, the editor locks up and throws an overflow exception followed by a crash and corruption of the existing project (i.e. the project crashes immediately on subsequent opening in Unity).

    I hope this issue can be resolved, but on a side note, is it possible to force the node graph to only allow port connections which will produce a resulting a-cyclic graph?

    Thanks in advance.
     
  48. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    If you are talking about graphs in graphs, there is no builtin support for it, but a lot of users have made it work just with a node with a public graph field. So it's definitely possible.
     
    CptKen likes this.
  49. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    The examples haven't been updated in years. I rarely do bug fixes on them as they were never intended as an end-product.

    But yeah, you can probably implement it in OnCreateConnection override by looping though all input connections recursively, keeping a HashSet history to check against.
     
  50. at1012

    at1012

    Joined:
    Mar 10, 2013
    Posts:
    6
    Thanks! This did the trick.