Adding Node in runtime

adammak

New member
Hi, ive been tinkering with Behavior Designer Pro to see if it works with my use case but seems like adding a node in runtime is not fully implemented? I want to save/load BehaviorTree in runtime and it works perfectly.
BehaviorTree has public void AddNode(ILogicNode node) but it adds node with Parent, sibling and runtime indexes as ushort.MaxValue even if i set these manually to point to proper parent/sibling like so:
BehaviorTree.AddNode(newAction, lastNode.ParentIndex, 65535, (ushort)(lastNode.RuntimeIndex + 1));
action.Initialize(BehaviorTree, action.Index); // doesnt seem to do anything in this case
BehaviorTree.ReevaluateSubtreeReferences(); // doesnt seem to do anything in this case
BehaviorTree.Serialize(); // doesnt seem to do anything in this case

No action is added and I'm getting error when refreshing Behavior Designer window:
[COLOR=rgb(184, 49, 47)]IndexOutOfRangeException: Index was outside the bounds of the array.[/COLOR]
[COLOR=rgb(184, 49, 47)]Opsive.GraphDesigner.Editor.Views.GraphView.LoadNode (Opsive.GraphDesigner.Runtime.ILogicNode node, System.Int32 index[/COLOR]
Some data is added to TaskData but i think im missing something.
Thank you in advance.
 
Adding runtime nodes are not currently supported. The only way to do this right now is to replace the nodes using a different subtree reference.
 
Thank you for quick response.

To specify: I meant either in runtime or in UnityEditor runtime. Even if i manually edit logic nodes and LogicNodeProperties? or perhabs add node after graph serialization and deserialize it? I know there is no official way of doing so, but i'm asking whether it is physically possible using some very hacky way.
 
You will need a LogicNodeProperties, but adding nodes outside of the editor wasn't in the design so I'm not sure what it will take.
 
Actually, thinking about this some more, it's going to require a lot of work. AddNode adds the node to the authoring data, but that gets translated to ECS components at runtime which you would then need to create and ensure is structured properly as well. Runtime node modification has been on my list for awhile, I just haven't gotten enough requests to justify it for the amount of work required. I'll think about it some more though.
 
Yes, the original version is easier. If you do a search for NodeData you should find some examples on this forum.
 
Back
Top