NodeCanvas Forums › General Discussion › Child nodes in my custom system
Hi guys,
I write my tree system to visualize data tree. I need in creating and childing nodes at runtime to their base node. So what the best way to do that?
I can create new node by graph.AddNewNode(MyTestNode)
, but I got exeption when I select this node in Graph window, because MyTestNode have public property like: public IMyInterface MyProperty { get; set; }
. So how to prevent parsing some public proprties by EditorUtils?
And how to addNewNode as child to other node (with connection)?
Sorry for the dumb questions.
Hello,
Are you creating your own node system?
You are probably using an old version of NC and that is why you are getting the error of EditorUtils parsing the public property. This has been changed and properties are no longer parsed.
Regarding creating a whole tree through code, the current API has some limitations especialy when it comes to assigning Task (actions, conditions). If you are creating your onw system where you wont use tasks, then you probably wont have any difficulties. It depends on the system.
The API for creating trees from code in runtime will be improved in the future to be faster (for example make use of generics)
You can connect 2 nodes together with ConnectNode(Node, Node). Here is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
using UnityEngine; public class CreateTree : MonoBehaviour { public Graph graph; void Start () { var node1 = graph.AddNewNode(typeof(MyNode)); var node2 = graph.AddNewNode(typeof(MyNode)); graph.ConnectNode(node1, node2); } } |
Using ConnectNode, node2 will be connected to the last port index of node1.
Let me know,
Gavalakis Vaggelis
Join us on Discord: https://discord.gg/97q2Rjh
Gavalakis, thank you very much!
Yes I’m creating my own node system to visualize my serialized game data.
So, one last question, can NodeCanvas sort all nodes positions? Currently all new nodes are instantiated at the same place.
You are welcome 🙂
No, currently there exit no auto position sorting for the nodes, since well, it’s primary designed to create trees from the editor window 🙂
If you want to position your nodes, or even create your own sorting method, use the nodeRect property of the node which is available only in editor (#if UNITY_EDITOR) and adjust it’s center (node.nodeRect.center) which is a Vector2. Top left of the canvas is 0,0.
Let me know if you have any questions.
Cheers!
Join us on Discord: https://discord.gg/97q2Rjh
Thanks!
Hey Gavalakis!
Is it possible to hide some nodes (which extended from my base node) from graph context menu?
Thanks!)
Sorry for the bunch of questions 🙂
1) How to disable creation new node from connection port in the other node?
2) How to disable node deleting?
3) How to disable connection deleting?
Hello,
No worries, but I am a bit confused 🙂
0. What do you mean hide nodes? Hide them in the graph?
1. What do you mean by disabling new node creation from connection port?
2,3. You mean disable the UI for deleting nodes and connections? Why you would want to do that? 🙂
Sorry, but I am confused 🙂
Join us on Discord: https://discord.gg/97q2Rjh
Sorry, but I am confused 🙂
Sorry, for that 🙂 Let me explain)
0. I mean hide some nodes from a context menu – http://i.gyazo.com/28667a1734a7489787544de527a823f6.png;
1. At now I can click on the port and create new node with context menu – http://i.gyazo.com/28667a1734a7489787544de527a823f6.png I want to prevent this action;
2,3. As I said above in my previous posts, I write my own Node System for my own data framework for the Unity. All instances of my framework creates at runtime. So my NodeSystem just visualize my framework instances relations tree. So I don’t need to remove nodes or connections from graph, because my graph builds in runtime automaticaly.
Don’t worry 🙂
So:
0. First of all, abstract node classes will not show. If you want to hide a non abstract node you can use [DoNotList] attribute on the node class and it will not be listed in the menu.
1. You will need to change the source code for that. Do you want to do that?
2,3. You will also need to change the source code for this.
I dont understand the practical reason that you want to remove those UI feature. I mean, if you don’t want to delete a node, then you can simply don’t delete it 🙂 and since it’s created at runtime there is no possibility that someone else is going to delete something that you don’t want to.
🙂
Join us on Discord: https://discord.gg/97q2Rjh