Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Simple node editor

Discussion in 'Extensions & OnGUI' started by unimechanic, Jul 5, 2013.

  1. brett_unity19

    brett_unity19

    Joined:
    May 1, 2018
    Posts:
    3
    First time post on Unity3D.... @Seneral - LOVE the node editor. I've been working with it for a couple of days and I'm looking for help on saving GameObjects referenced on a node. In my node definition, I have this variable name:


    [SerializeField]
    public GameObject ObjName;


    And in NodeGUI(), I have this:

    ObjName = (GameObject)EditorGUILayout.ObjectField(ObjName, typeof(GameObject), true, GUILayout.Width(250f), GUILayout.Height(20f));


    What else do I need to do to get the object to be saved? I suspect I'm not registering it correctly with the framework but didn't see how to do that.
     
  2. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,124
    Just about to leave:p
    Theoretically it's correct, but if that GO (or any other object) is stored in a Scene instead of the AssetDatabase (like Prefab), you can't reference it while the Canvas is save in the AssetDatabase. That would create a reference that couldn't be resolved when that specific scene is not loaded.
    Instead, you have to save the canvas aalon with that GameObject in the same scene. Sometimes that conflicts with other design/plans, but it's the only way apart from saving just the name/etc. and finding it in the scene (assuming that scene is loaded) which would be better for managers that are in every scene.
    So you can save in the scene from tr same popup, it will simply create an empty object in the current scene with a wrapper component that holds a copy of that canvas. Unity will now save it correctly inside the scene an maintain scene references!
    Hope that helps,
    Seneral
     
  3. brett_unity19

    brett_unity19

    Joined:
    May 1, 2018
    Posts:
    3
    Oh. Glad I asked! Thanks so much.
     
  4. KrytalityStudios

    KrytalityStudios

    Joined:
    Sep 12, 2016
    Posts:
    16
    I have a quick question on the implementation details of basically only drawing a certain portion of the canvas. The situation is this, right now I'm implementing the different nodes to be saved to my database, and I've changed the database idea up a little so that there is a limit on one database per project. Since that is so, I need to have some way to draw only a certain portion of the canvas, say just a single conversation and be able to switch between the different conversations to edit. I was just wondering about the implementation into doing that.
     
  5. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,124
    I'm not sure about your implementation, but you probably want to take a look at NodeEditor drawing loop, where the data of the canvas is processed. You probably have to select the correct NodeEditorState (view transformation, etc), the respective nodes and their connections only depending on what you want to draw.
    Sorry, on my trip atm, can't help you on code level.
     
  6. KrytalityStudios

    KrytalityStudios

    Joined:
    Sep 12, 2016
    Posts:
    16
    Thank you for your response! And that's fine because I have decided to roll my own sort of implementation of the Node Group class, called something like the NodeGroupVisible class or something like that, and basically the class will place all nodes created when it is active into its nodesToDraw var or something, and then that will allow the NodeEditor class to know what to draw in a nutshell. This will be the basis for allowing the UI to select a certain conversation or quest, and then only displaying the nodes related to that conversation or quest.

    The only thing is, and I may figure this out before you respond, but will not displaying the nodes stop them from getting messages? If so I guess somehow I could just create maybe something in the Node class that will make it stop responding to messages, but I don't really know. And it may not even be important o_O.

    Once again you really don't have to respond on a trip lol, but thanks anyway :)!
     
  7. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,124
    Ya I'll try! :)
    If try are not drawn, there are no GUI controls at all, so they cannot be altered at all, if that is what you mean by receiving messages. Of course of you have a traversal routine in place, that would atils consider all notes (like the ccalculation routine). Also, if tgey have connections to visible nodes, those could of fourse interact with the invisible onces, in theory. But from the GUI perspective, they are simply non existent.
     
  8. KrytalityStudios

    KrytalityStudios

    Joined:
    Sep 12, 2016
    Posts:
    16
    So there is one issue right now, I have basically created a new list of groups that do what I said, but the issue is that the references to the nodes and the node canvas parent are not being saved in the group class I made, and I have marked it as serializable.

    So my question is how do you save this kind of stuff, because marking the group class as serializable is not saving the references to any SO objects.

    And so basically do I change it to a SO itself? This seems fairly logical but I will have to modify the save manager.

    I have tried to work around this by having some unique IDs for every node, but that has proven to be a pain so my options are as follows:

    Use unique IDs for every node and just work it out.
    Change the group class to an SO and modify the save manager a little (or maybe a lot idk)
    Just use the view transform to focus on a certain portion.
    Or, as I write this I thought this, do some trickery within the node class and do something similar to the dialogue editor example and just basically have some dialogue start node or quest start nodes, and all the ones connected are a part of the conversation/quest, allowing the node editor to only draw those groups of nodes in particular. Which seems like a good idea but yeah .

    Thanks again. Cheers!

    Quick edit: I have found something that may work with the unique ID solution and I am going to try it.
     
    Last edited: Jul 15, 2018 at 10:21 PM
  9. brett_unity19

    brett_unity19

    Joined:
    May 1, 2018
    Posts:
    3
    I'm using the node editor to describe network diagrams for building systems and I was looking for advice on how to represent wires that branch. A pipe or a conduit will branch off and I want to represent that notation in the node editor. In current practice, this is done using a solid dot. I can cope with a very small node.

    Anyone have any advice on how to represent this type of notation? (You can see the solid dots on this image...)

     
  10. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,124
    e
    Sorry for the late reply, am back from the trip now and working again:)
    It has to do with how the unity serializer works and how I adapted the system for working copies.
    Long story short, when saving the canvas, all scriptable objects get duplicated manually (so you are not working on the SO saved in the asset database directly) and all references to them have to be restored. So if you are referencing any SO, you have to restore the references. If you actually implement a new SO type, you additionally have to make sure it gets duplicated and recorded, too. Nodes and stuff have these two callbacks to record and restore those references incase they are referencing SOs directly.
    Your best bet would be to modify the save manager directly to replace the node references in your class with the new references. This block in the CreateWorkingCopy function is responsible for that, just use the following line:
    newRef = ReplaceSO (allSOs, clonedSOs, oldRef);

    where oldRef is the old node and newRef is the cloned node. Update every field in your class like this and it will work:)
    Unfortunately I don't think a generic, reflection based solution would be suitable here for finding and handling SOs correctly, since it would add quite an overhead compared to occasional manual additions.
     
  11. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,124
    Aren't multiple outputs functionally the same? You would have two wires all the way, but it would work. You can of course add these dots as an additional entity to the drawing mechanic, a simple class should work. Only problem I see is there is no notion of a connection so far, only for knobs that connect in between, so you have to figure out where to store it.

    One option would be to add a struct list on a knob which holds information like:
    list int outputsToCombine; vector2 position

    And then the drawing routine (called from here) would first go through these and draw a single connection to that position and continue the outputs from there (maybe choose line instead of bezier, or even a new form like in the above diagram).

    One problem: Currently, those connections are drawn twice, from both knobs side once. Hadn't that figured out when remaking the knob system recently, so maybe now is the point to fix that aswell. That would make it implementing easier.

    If you need help, please tell me.
    Seneral