Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Simple node editor

Discussion in 'Immediate Mode GUI (IMGUI)' started by unimechanic, Jul 5, 2013.

  1. DiRoll

    DiRoll

    Joined:
    Jan 5, 2014
    Posts:
    32
    Could someone implement more GUIExt controls like button, toggle?
    I would do it myself but have not yet figured out the code.
     
  2. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    I will be back working on that soon. It's pretty simple after you got behind it, actually. First, you need a way to design your stuff, like a button here and so on. Then you have to make sure it react correct (like making sure it looses control properly). In some cases you also need to store some data for each individual control, like in the float field in GUIExt which stores the typed content. Float Field is actually a pretty complicated example, showing each of those features.

    I'm working on a seperate OverlayGUI class handling everything overlay-like, replacing GenericMenus, Tooltips, Popups, etc. which isn't influenced by scaling. After that I'll continue to port stuff from Editor GUI to ingame GUI.

    Additionally, why would you want to port Button and Toggle? makes no sense, you can just use ingame GUI stuff. GUIExt contains only stuff limited to EditorGUI.
    Yet missing are for example Popups, ObjectFields and other fields, several sliders like MinMax slider, ...; Using reflection most of that stuff is pretty easy to implement, and stuff that refeences the internals has to be replaced.
     
    Last edited: Oct 1, 2015
  3. Gru

    Gru

    Joined:
    Dec 23, 2012
    Posts:
    138
    Thank you for this nice extension. But...

    I have spotted quite a few bugs:
    1) When creating node groups and canvas is added, all the connections from the original canvas are drawn over the ones in a new canvas.
    2) When loading an asset in a node group, all the elements and connections are offset.
    3) There seems to be a floating point error when zooming in/out, the value fixes to 0.99999 instead of 1.
    4) When creating an Example node, if it's done while zoomed out the text is blurry when zoomed back in, and it stays that way even if the asset is unloaded then loaded.
    5) I have managed to "screw up" the zoom and handle size input boxes (a couple of times). Don't know how, but they became uneditable. The same thing happened once with the State node. This persists on asset load/unload, and haven't found a way to repair it. Scroll still works, but this zooming business seems like more trouble then it's worth.
    6) When loading calculation canvas nothing happens, the current canvas is not unloaded. Loading custom canvases seem to work.
    7) Connections are drawn over the Window header when it's floating.
    8) Node input/output connections are drawn over everything.
    9) When the canvas is saved it's name above the buttons is not updated.

    Also, I don't really like the way that assets are saved all the time. This is very confusing because Save Button actually doesn't do anything; also if an asset gets screwed like in my case it's game over, there is no prior version to come back to unless I've saved the asset under different versions which is a bad idea. I would vote it to be saved on Save button.

    Is there a way to make vertical Nodes?

    I'm available if you want more info, and if the extension is still maintained.
     
  4. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    Hi Gru,
    Thanks for your input:)

    1) and 2)
    Node groups are not yet fully supported - actually, I hid them in the latest builds, though I seem to have forgotten it in the last one... Node Groups were just a test, there are still alot of features that need to be implemented along with it to make it reliable:)

    3) It's simply floating point unprecision, I simply add scroll values ontop, so it's not really my fault;) I'll add some rounding to it.

    4) I cannot reproduce that... It would be a fault by unity's scaling support either way. Can't really do something about it...

    5) Never happened to me so far, curiously. Can you somehow find a way to reproduce that, or at least describe exactly what is happening? I guess from your last sentence it has to do with scaling, right?

    6) Is there an error in the console? That'd be my only guess, the example canvases should and do work on my build...

    7) I didn't have implemented clipping on my custom bezier drawing formula yet, that's why. I'll try to do that soon. If it annoys you too much, you can replace the code in NodeEditorGUI.cs/DrawBezier with Handles.Drawbezier. Does not work at runtime though, that's why I implemented my own...

    8) That's because of the render order, obviously. That constellation was the one with the least annoyances... I'll try to find a new way to render everything, so such things dissappear.

    9) It's just the fault of the example window. It's an easy fix though, just replace the first line of the DrawSideWindow func in Editor/Node_Editor/NodeEditorWindow with
    Code (csharp):
    1. GUILayout.Label (new GUIContent ("Node Editor (" + mainNodeCanvas.name + ")", "The currently opened canvas in the Node Editor"), NodeEditorGUI.nodeLabelBold);
    That window is just an example, the rig around the actual canvas is all up to you how you design it. That's why I didn't really cared about design yet, for a real situation a toolbar and improved side window is probably the way to go.

    Finally, regarding the save system, I agree it's annoying. Not only that, the more nodes are on the canvas, the longer it takes to operate on the canvas. That's because scriptable objects keep the reference to the asset in the project, so after a save, everything to the object gets saved to the asset. I'm searching for a way to break that link to allow for the way to save you described...

    Finally, vertical nodes are theoretically easily added. You would need to make some changes to the framework atm, I'll add that in the next update.

    Important for mac users: There was an issue case recently with reflection problems, which I suspect to be because of Mac. I don't have any macs to test on, but maybe you have;) Is any other Mac user experiencing the problems mentioned in the issue?

    Regarding to the maintenance of the extension: You might have noticed I'm not doing that much updates recently, that's because I'm working on other extensions yet unreleased. I'm still dedicated to the Node Editor and I'll still respond to your concerns, but I'll likely won't continue on additional features like fully featured state nodes or groups for now.
     
    Last edited: Oct 13, 2015
  5. Gru

    Gru

    Joined:
    Dec 23, 2012
    Posts:
    138
    Thanks for a thorough and quick response!

    Just a quick update, I tried it again on Win 8.1 (before I was on Win 7):
    4) I zoom all the way out, create a node, zoom back in. The node header text refreshes when clicked/unclicked, but the text inside node body is a tiny bit blurry. This one is really not a big deal for me.

    5) I just created an input node on the empty canvas and could not edit input boxes on the sidebar, happened on both my PCs. Those input boxes just don't react to clicks (don't become editable). Scrolling still works to zoom, and input node works fine.

    6) Nothing is printed to the console, same on both PCs.

    Since it's not mission-critical for me right now, I will probably be checking the extension again sometime in the future.
     
  6. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    Ok, I'm working on a completely new save/load system right now:) I manually create a copy when loading and saving, which breaks the link to the asset.

    4) Could only reproduce that on the calculation node. My first thought was it is because of the floating point unprecision in the scale, but that didn't turn out to be the case.

    5) Ok I think be both talked about something different. If you mean the drag handles for connections on the nodes - I absolutely see no reason why this should not work. If you mean my custom float inputs - I experience the same, I'll fix it:) The problem seems to be that when any of my custom fields are on the screen (any node in this case), keyboard control plays crazy. I fixed that:)

    6) Take a look at the save file please. When no errors occur, there are only two options: You canceled loading (not selecting any path) or the save file is empty (no objects to load).

    I'm working on an update aswell as fixes for above problems;)
     
  7. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    I just published the new Save/Load system, you now have to save explicitly:) That means way better performance, too.

    @Gru Do you still experience the loading problems for example canvases with the new update?
     
  8. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    Another update out, adressing most issues you were noting Gru:)
    I reworked the connection placement, which is now alot better and safer and finally allows placement on any side of the node with correct orientation:D
    I also added the option to override DrawNode to customise the node appearance. I included a canvas and the node AllAroundNode to showcase this:
    Screenshot1.jpg
    That looks weird, right? ;)
    Disabled calculation and allowed recursion for this node, additionally it overrides DrawNode which disables the header and hides the body:) On each side of the node is an input and an output, each with correct orientation for both connection and knob texture, without much additional work:) As I tweaked a little bit how NodeInput's and NodeOutput's are handled, you'll probably can't open old saves anymore...

    I also added a compability mode for GUIScaleUtility, which should automatically trigger if a problem occurs, as described here.

    And finally, double clicking on a node canvas asset now opens the Node Editor window and loads the canvas automatically:) Though I did not added loading when the asset is just selected (as in mecanim fE), as progress might be lost.
     
  9. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    I committed an update which greatly increases scaling system performance, thanks to Fast.Reflection by vexe:) It gives up to 20x better performance than ordinary reflection calls, and keep in mind this gets called every GUI call and for each top group once! You'll find his script in the utility folder:)
    Btw, added two more scripts to it to keep the common tasks clean, ResourceManager which will get some features soon, aswell as OverlayGUI, which basically is a replacement for every GUI element that's not affected by scaling (Popups, GenericMenus, Dropdowns, etc.). They are all basically using the same shared 'engine'.

    Besides that, I was not developing too much on Node Editor recently.
    I may add undo support in the future (really necessary, I know;) ), probably using my UndoPro system that I'm developing right now, which is an action-driven undo system that integrates into the default Undo system seamlessly:)
    Seneral
     
    Gekigengar, UnLogick and manpower13 like this.
  10. DiRoll

    DiRoll

    Joined:
    Jan 5, 2014
    Posts:
    32
    Great! Seneral you need to add a link to repository to signature/recent post so that users do not have to look for a link across thread.
     
  11. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    I have one in my signature;) First line, Repository

    Btw also improved performance again by alot, I fully implemented the ResourceManager features yesterday. That's especially critical for texture management, as I perform alot of texture modifications in NodeEditor: Tint, Rotate, ... That adds up quickly. Now, I make sure each texture is only tinted and/or rotated once, by adding a record for each texture with corresponding modifications. Sounds complicated, but it's worth it. No need for tinting line textures each frame and similar stuff;)
     
  12. DiRoll

    DiRoll

    Joined:
    Jan 5, 2014
    Posts:
    32
    Awesome! I have to wait when You add more controls and I'll add the editor in my project (to adjust map generation)
     
  13. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    What do you mean with more controls? If you mean the controls in GUIExt like you mentioned in the first post on this page, then you're probably misunderstanding something;) They are conversion for editor-only gui stuff, you can still use GUILayout liek in any other GUI code
     
  14. DiRoll

    DiRoll

    Joined:
    Jan 5, 2014
    Posts:
    32
    Ok, I understand. I ve downloaded repositorry and get error - "Assets/Node_Editor/Framework/NodeInput.cs(7,34): error CS0246: The type or namespace name `NodeKnob' could not be found. Are you missing a using directive or an assembly reference?"
     
  15. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    Sorry, was missing that. I fixed that with another update.
     
  16. DiRoll

    DiRoll

    Joined:
    Jan 5, 2014
    Posts:
    32
    More errors:
    Assets/Editor/Node_Editor/NodeEditorWindow.cs(137,171): error CS0117: `NodeEditorFramework.NodeEditor' does not contain a definition for `knobSize'

    Assets/Editor/Node_Editor/NodeEditorWindow.cs(137,63): error CS1502: The best overloaded method match for `UnityEditor.EditorGUILayout.IntSlider(UnityEngine.GUIContent, int, int, int, params UnityEngine.GUILayoutOption[])' has some invalid arguments

    Assets/Editor/Node_Editor/NodeEditorWindow.cs(137,63): error CS1503: Argument `#2' cannot convert `object' expression to type `int'
     
  17. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    Sorry about all the inconveniences, I should have checked if it works. I have several things I still keep from committing as they are not yet finished at all, mostly small changes, so I keep missing the things I want to commit:( But it does work now.
     
    manpower13 likes this.
  18. DiRoll

    DiRoll

    Joined:
    Jan 5, 2014
    Posts:
    32
    1. I put a button on my custom node and I need to show new window when it is clicked. How could I do that? (I want to have a tile array in my node and each of them has a "pick tile" button showing window with tileset).
    2. And I thinking about dynamic node rect size, I have array of items and when adding a new item, it does not fit in height:oops:
     
    Last edited: Nov 3, 2015
  19. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    Hi,
    1) It's the same as you would in your normal GUI -
    Code (csharp):
    1. TilePickWindow tilePicker = EditorWindow.GetWindow<TilePickWindow> ("Pick a tile");
    Though, as this makes use of EditorWindow it cannot be used at runtime, you would enclose that with #if UNITY_EDITOR to make sure;)

    2) I did not find a way yet, that would indeed be great... If I may explain the problem: BeginGroup does obviously not account for that straight away, whereas BeginVertical/Horizontal do - but I cannot specify a position for them:( I might take another try and either look into finding a hacky way to use the auto-sized BeginVertical/Horizontal or to calculate the group size myself (pretty hard)... But taking that into consideration, that would be an easy thing if we had the source:( But afaik everything related is native:(
     
  20. helarts

    helarts

    Joined:
    Jun 12, 2013
    Posts:
    6
    Hi Seneral,
    I started to mess a bit with your node editor, pretty cool project.
    Few suggestions:
    - Use GUI.Box instead of GUI.Window to draw the nodes, it needs a bit of work to handle the drag&drop and sorting but fixes the issue of editing a node's parameter and the value is changed on another node, I think this is caused by GUI.Window's "feature click-to-focus".
    - Use GenericMenu instead of EnumPopup to workaround the misplacement caused by the zoom ( http://answers.unity3d.com/question...n-editorguienumpopup-insi.html#answer-1093252 )

    Cheers
     
  21. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    Thanks helarts:)
    I already abandoned GUI.window long ago, because of missing flexibility;) I did not experience the problem you are mentioning though, can you describe it more precisely how it's triggered? It may be a problem not of GUI.window, but of my implementation

    I'm working on a solution for your second point - basically, I am going to use GenericMenu, but my own one that works at runtime. I recently added OverlayGUI to the Node Editor, which is a utility that should control every overlay stuff (GenericMenu, Enums, Popups, etc) of the NodeEditor, which is then both avaible in Editor and at RT. I already layed the fundamentals of all that, which is the PopupMenu class - an engine that will be used for all Overlay GUI stuff. I still have to implement the appropriate Popups though;)
     
  22. DiRoll

    DiRoll

    Joined:
    Jan 5, 2014
    Posts:
    32
    I know how to call Editor window, but I want to call it from my custom node script (Assets/Plugins/Node_Editor/Nodes/CustomFolder/CustomNode.cs).
    TilePickWindow editor window located in Assets/Editor and it outside of scope for my custom node script.

    Of course I can put my custom node script inside Editor folder.
     
  23. helarts

    helarts

    Joined:
    Jun 12, 2013
    Posts:
    6
    Great, I didn't update the editor for 2 weeks or more, I'll check the latest.
    Not the best way to show that bug but basically edit a value in node A with the mouse, then edit another value in node B and see the value changes on the previous field you edited in node A instead of the one you are currently trying to modify. It did that all the time unless you click in the node you want to edit before modifying a value, to update the focus in the right window I guess.

     
  24. DiRoll

    DiRoll

    Joined:
    Jan 5, 2014
    Posts:
    32
    I have a problem fith focus too. I have 2 nodes with int fields and after changing focus I can get this situation
     
  25. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    @DiRoll Yes you'd have to move types referenced in nodes into the Plugins folder or, the other way around, move the nodes outside of the plugins folder. Nodes can be outside and still work, as I search all assemblies for them, but you can't directly access anything outside the plugins folder when inside it, because of the assembly load order.

    Regarding the bug, it's harder to fix than I thought. I tried to manually loose focus when selecting a node, which does work with float fields and other stuff. But the same problem still remains with the popups - when I click them, no click callback is send to the node, but the controls get still exchanged. My only explanation is that node order gets changed between some events where they shouldn't, potentially confusing the GUI system so it cannot order the control IDs correctly. No real idea so far, though:(
    I'll be able to sort that out when I switch to custom popups though:)
     
    manpower13 likes this.
  26. DiRoll

    DiRoll

    Joined:
    Jan 5, 2014
    Posts:
    32
    How can I create a "window" based on the node? Let me explain - if I click on the button located on the node and call my editor window, it remains the same size regardless of the scale of the canvas.
     
  27. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    You mean with the same size in regards to the scale/zoom, you want your seperate Editor window opened from a node to scale with the zoom of the Node Editor window? That's not possible and not meant to be that way either;) Only stuff that gets drawn in the GUI of Node Editor gets scaled - a seperate Edior window doesn't.
    With "window based on a node" you mean like a subwindow? You can call GUI.window from inside a node - that should be totally fine:) Let me know if that isnt what you want to achieve!
     
  28. DiRoll

    DiRoll

    Joined:
    Jan 5, 2014
    Posts:
    32
    Yes I want a subwindow) I'll try to use GUI.window.

    Found a bug:
    If I create, for example, 2 custom node script with same path, I mean [Node(false, "Example/Example Node", false)]
    in Node Editor context menu they are both highlighted when I move mouse over one of the items.
     
  29. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    Ok I will check that tommorrow - will have to take a look how the default GenericMenu reacts on such duplicate paths and replicate it;)
     
  30. DiRoll

    DiRoll

    Joined:
    Jan 5, 2014
    Posts:
    32
    Can't get GUI.window to work:(
     
  31. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    I'll take a look and send you an example when I get back home later:)
     
  32. DiRoll

    DiRoll

    Joined:
    Jan 5, 2014
    Posts:
    32
    And please write an example of creating an instance of a node by clicking the button on the other node.:D
     
  33. pmh-pereira

    pmh-pereira

    Joined:
    Jan 9, 2013
    Posts:
    1
    Hello Seneral,

    I just found about your Node Editor (was considering implementing my own) and decided to give it a shot.

    I tried to run the example demos, but nothing happens, not even in the console.
    Selecting each of the 3 files and checking the Inspector, I noticed there isn't a script associated with them.


    Edit:
    This happens because the guid references in the *.asset files are different from the guid that Unity generates for me when I add the files to the project.
    The solution is for Seneral to add all the *.meta files to the GitHub repo. These files are generated when the Version Control Mode is set to Visible Meta Files.
     
    Last edited: Nov 9, 2015
  34. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    I already include meta files for the textures, but didnt know the saves need them, too. That means, I need to include the metas of ALL scripts in order for the saves to reference them correctly:( Thanks for the report though;)
     
    pmh-pereira likes this.
  35. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    Sorry for the late reply, here ya go:)
    This will create another node of the same type below the current one
    Code (csharp):
    1.  
    2. // In NodeGUI
    3. if (GUILayout.Button ("Create New Node"))
    4. {
    5.      Node node = Create (rect.position + new Vector2 (0, rect.height+20));
    6.      node.InitBase ();
    7.      NodeEditorCallbacks.IssueOnAddNode (node);
    8. }
    9.  
    If you want to create a node of another type:
    Code (csharp):
    1.  
    2. // In NodeGUI
    3. if (GUILayout.Button ("Create New Node"))
    4. {
    5.     Node node = NodeTypes.getDefaultNode ("calculationNode"); // Pass the id of the node you want to create
    6.     if (node != null)
    7.     {
    8.         node = node.Create (rect.position + new Vector2 (0, rect.height+20));
    9.         node.InitBase ();
    10.         NodeEditorCallbacks.IssueOnAddNode (node);
    11.     }
    12. }
    13.  
    I cant get GUI.window to work right away, either. I'll have to take a closer look when I have more time:)
    Seneral
     
  36. DiRoll

    DiRoll

    Joined:
    Jan 5, 2014
    Posts:
    32
    Thank you:)
    I try to solve problems with a focus elements, but at the moment there is no progress. Maybe you should use the GUI framework, for example asset store link.
    If you place two identical nodes one over the other, when you click on the textfield - the lower node textfield get the focus. I understand this is due to the fact that first lower node handles the event.
     
  37. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    Unity GUI is a pain sometimes, true. But I'm not sure if switching to a framework that basically relies on Unity GUI aswell helps at all, idk. I might consider that, but first I would rather stay with the default. Because, what does that mean to developers using the Node Editor Framework? They had to program the GUI using that framework, too, which is not appreciated by everyone...
     
  38. DiRoll

    DiRoll

    Joined:
    Jan 5, 2014
    Posts:
    32
    Then I have to wait when you come up with solution to this problem)
     
  39. LazyMan

    LazyMan

    Joined:
    Dec 7, 2013
    Posts:
    22
    Hello everybody!
    What i can to do, If i need to serialize custom scriptable object in node?
    So, i'am gonna to explain...

    Base class:

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3.  
    4. using UnityEngine;
    5.  
    6. [Serializable]
    7. public abstract class ModuleBase : ScriptableObject
    8. {
    9.      //...
    10. }


    And other modules from baseclass...

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. using System.Collections;
    4.  
    5. public class Fbm : ModuleBase
    6. {
    7.     //...
    8. }


    Atm i already have custom nodes and custom ConnectionType for these modules:

    Code (CSharp):
    1. //...
    2. public class NoiseType : ITypeDeclaration
    3. {
    4.      public string name { get { return "Noise"; } }
    5.      public Color col { get { return Color.yellow; } }
    6.      public string InputKnob_TexPath { get { return "Textures/In_Knob.png"; } }
    7.      public string OutputKnob_TexPath { get { return "Textures/Out_Knob.png"; } }
    8.      public Type Type { get { return typeof(ModuleBase); } }
    9. }
    10. //...


    Different custom nodes have different modules.
    Btw, my current solution is messy code inside the canvas Save/Load mechanism... So messy to show up it here :)
    Thank you in advice! Sorry for my English :)
     
  40. LazyMan

    LazyMan

    Joined:
    Dec 7, 2013
    Posts:
    22
    Oh. Solved. My bad. Simply add ModulaBase to Node class.
    So i can easy serialize it.
    Thx for editor!

     
  41. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    Wow looks great 'Lazy'Man ;)
    But, I have to dissappoint you, simply adding the scriptable object to node does not work straight away:(
    1. Data will be lost after restarting unity - because you did not explicitly saved the scriptable object as an asset, it will not be saved like the others.
    2. Assuming they get saved, even after saving to multiple locations, the saves will reference the same scriptable object, so doing a change inside the Node Editor window to that instance will also make those changes to the saves without explicitly saving...

    To fix that, you either have to integrate that into the Save/Load function, or you can take the NodeEditorCallbacks.OnSaveCanvas (NodeCanvas canvas) callback. Using the second method, adding that static class somewhere should help you (not tested):
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4. using NodeEditorFramework;
    5.  
    6. [ExecuteInEditMode]
    7. public static class SaveNodeSOs
    8. {
    9.     // Static class contructor, gets called on every assembly reload
    10.     static SaveNodeSOs ()
    11.     {
    12.         NodeEditorCallbacks.OnSaveCanvas += HandleSOSaving;
    13.     }
    14.  
    15.     // Function to handle custom save operations for a canvas in
    16.     public static void HandleSOSaving (NodeCanvas canvas)
    17.     {
    18.         // canvas is NOT the canvas loaded in the window, but the one saved to an asset and as such a copy of it
    19.         foreach (Node node in canvas.nodes)
    20.         {
    21.             // Filter my custom node
    22.             if (node.GetType () == typeof(CustomNode))
    23.             {
    24.                 CustomNode myNode = node as CustomNode;
    25.                 if (myNode.mySO != null)
    26.                 { // Here we make it save correctly
    27.                     myNode.mySO = Object.Instantiate (myNode.mySO); // Pass a copy of my SO to the save asset, so modifying the loaded SO does not affect the saved one
    28.                     AssetDatabase.AddObjectToAsset (myNode.mySO, canvas); // Also, you need to save that copy to an asset, so it can survive Editor restarts
    29.                     myNode.mySO.hideFlags = HideFlags.HideInHierarchy; // Then hide it so the save asset appears as one rather than a collection of assets in the project view
    30.                 }
    31.             }
    32.             // You could add other node types that need such custom saving afterwards in an else-if statement, and if it gets long, a switch statement
    33.         }
    34.     }
    35. }
    36.  
    Using the comments it should be easy to understand I hope:)
    Tell me if that does the job or you need additional help:)
    Seneral
     
  42. LazyMan

    LazyMan

    Joined:
    Dec 7, 2013
    Posts:
    22
    Seneral, Thank you for a reply...
    I disappeared. Realy.
    Btw i think that my mechanism working good. Need to test out that.
    So i can share my piease of project...
    Can you help me? Working with ScriptableObject is new for me...
     
    Last edited: Nov 21, 2015
  43. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    Well, if it works ok for you, no problem:) Some things you have to take care of are, as mentioned above, the copying and saving seperately and the hiding in the hierarchy. Anyways, there are several solutions for that and the above script is the most clean solution I guess - until I implement the automated deep-copying and saving of scriptable objects, which should be easy to make with a tat of reflection;)

    And what kind of help do you need?
    Seneral
     
  44. LazyMan

    LazyMan

    Joined:
    Dec 7, 2013
    Posts:
    22
    Ya. lol,.tested out. My method does not work as I expected.
    So your method working good, but it is like "Strong Forward To Hell", bec. a lot of code for each custom node... Spaghetti code! :D

    Can't wait :)
     
    Last edited: Nov 21, 2015
  45. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    For your information why I did not work on Node Editor the last two weeks approximately:
    I'm in the final sprint before the end of a competition I'm participating in, which is why I was concentrating on that. I'll continue working a bit on Node Editor the next week again, though I will only have full time to work freely another two or three weeks after, unfortunately.
    Hope you understand and again, you'all are invited to contribute, too;)
     
    manpower13 likes this.
  46. LazyMan

    LazyMan

    Joined:
    Dec 7, 2013
    Posts:
    22
    I'm happy! So i can help you inplement some sheet for your Node Editor.
    See you on GitHub!
    Pm me in case...
     
  47. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    Hey guys, I'm just posting today because I found out something that I really didn't expect to work: Javascript nodes!

    I had the idea of creating a Node wrapper around TerrainComposer, which is written in JS. At first I thought I could cringe myself through by adjusting the compile order, but that did not really work out very well.
    So I tried something completely arbitrary, as I judged it at that time: I tried to create a JS node in the C# Node Editor framework. It's clear that JS can access C#, but not vice versa without adjusting load order.

    So the problem was: Will my reflection based Node type fetching be able to fetch that JS node and will I be able to access and treat it normally using the C# Node base?
    This is the code I came up with first and finally, a modified version of the Example Node:
    Code (JavaScript):
    1. import NodeEditorFramework;
    2.  
    3. @Node (false, "JS Node", false)
    4. public class JS_Node extends Node
    5. {
    6.     public final var ID : String = "jsNode";
    7.     public override function get GetID () : String { return ID; }
    8.  
    9.     public override function Create (pos : Vector2) : Node
    10.     {
    11.         var node = CreateInstance ("JS_Node");
    12.    
    13.         node.rect = new Rect (pos.x, pos.y, 150, 60);
    14.         node.name = "Javascript Node";
    15.    
    16.         node.CreateInput ("Value", "Float");
    17.         node.CreateOutput ("Output val", "Float");
    18.    
    19.         return node;
    20.     }
    21.  
    22.     public override function NodeGUI ()
    23.     {
    24.         GUILayout.Label ("This is a JS Node!");
    25.  
    26.         GUILayout.BeginHorizontal ();
    27.         GUILayout.BeginVertical ();
    28.  
    29.         Inputs [0].DisplayLayout ();
    30.  
    31.         GUILayout.EndVertical ();
    32.         GUILayout.BeginVertical ();
    33.    
    34.         Outputs [0].DisplayLayout ();
    35.    
    36.         GUILayout.EndVertical ();
    37.         GUILayout.EndHorizontal ();
    38.    
    39.     }
    40.  
    41.     public override function Calculate () : boolean
    42.     {
    43.         if (!allInputsReady ())
    44.             return false;
    45.         Outputs[0].SetValue.<float> (Inputs[0].connection.GetValue.<float> () * 5);
    46.         return true;
    47.     }
    48. }
    Guess what? It works !!!
    That opens up alot of possibilities, doesn't it?
    But, of course you're right... JS is creepy as hell;)
    But one thing to note (important), we have to care atleast a little bit about the load order: The Fetching algorithm is compiled in the first phase out of four (check this page out), so the JS Node has to be in either the second, third of last phase of compilation! That means, outside the Plugins/Standard Assets/Pro Standard Assets folder and/or inside the Editor folder!

    Seneral
     
    Last edited: Dec 6, 2015
  48. crdmrn

    crdmrn

    Joined:
    Dec 24, 2013
    Posts:
    60
    Hey Man,
    First of all, thanks for your amazing work :D
    Then: did you notice that the node canvas refreshes everytime you open a new scene?
    is there a way of avoiding this?
    Thanks!
     
  49. crdmrn

    crdmrn

    Joined:
    Dec 24, 2013
    Posts:
    60
    Since I spent a bit more time on it, it might be just me, but I can't really grasp how the saving of the canvases works.
    I'm trying to instatiate a node for every scene in the buildsettings and add inputs according to the items in the scene itself. The thing is, when the editor loop goes on to the next scene, the canvas somehow refreshes in the wrong way and the code crashes. Also, even outside this loop, if you open a random canvas and then switch to anouther unity scene, the opened canvas will be lost as soon as you click on the node editor tab again. Is this supposed to be like this?
     
  50. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,185
    Hi Troy,
    first of all, the saving system is probably the most simplest;) Each time you save, a copy is created, and a copy is loaded when you load a canvas. The problem you're describing is a bug, where GUI elements like textures get unloaded for some reason when I open another scene. I'll take a look at that:)