How to edit Behavior Tree and Reload Behavior Component at runtime?

CherryBone

New member
I found that I can not edit Behavior Tree at runtime (Add/Delete Nodes), but sometimes I do not need the tree to be update because it may cause some unknown problems, but I think I can recreate a new Behavior Component when I change the Behavior Tree, but for some reason, the editor seems to be locked when the game is plaing? It comfused me for a while but I can not see the source code of the editor, so is there some way to satisfy the needs of reload when game is playing?

------

Sorry I forgot to describe minutely, I want to achieve the following operation:

When the game is running
1. Add a sequence and a task for a monster, and then reconnect some node.

2. Delete node (though it could be replaced by "mute").

3. Modify default value of nodes (now it is already could be done).

4. All changes above could be saved to the bevaviorTree.asset as externalBehavior file


And the purpose of these operation are simple, I don't want to relaunch the game to make some change to behavior tree bacause relaunching gaming wasted too much time, and I just want to change the behaviorTree of an object even though I need to recreate a behavior component, and it would save a lot of time.
 
Last edited:
When the behavior tree is loaded it creates all of the necessary data structures so you cannot add/remove nodes from the editor. At runtime you can dynamically load external behavior trees with the Behavior Tree Reference task but this looks like it is something different compared to what you are trying to do. Enabling/Disabling the node within the behavior tree does work at runtime though so if you hover over the node you can disable it on the top right. As you mentioned it is also possible to change the values.
 
When the behavior tree is loaded it creates all of the necessary data structures so you cannot add/remove nodes from the editor. At runtime you can dynamically load external behavior trees with the Behavior Tree Reference task but this looks like it is something different compared to what you are trying to do. Enabling/Disabling the node within the behavior tree does work at runtime though so if you hover over the node you can disable it on the top right. As you mentioned it is also possible to change the values.
Thank yo, so if We want to add/remove nodes from the editor and save the bt.asset at the same time and at the runtime, it needs additional development? Or it may be impossible to complete because of the framework? Our team are testing the plugin and we are afraid of waisting time at reloading of this plugin (ps. We think the Enabling/Disabling and Changing Value are not enough for our great demand).

More Info:
I mean, when the game is running, we don't need to add/remove nodes from the editor to the running behaviorTree, we only need to change the external behavior tree ".asset" source file on the disk, and after that, we could reload the .asset file and update the new add/remove changes to that actor.(we think it is theoretically feasible so we are confused why this plugin couldn't at the latest version)
 
Last edited:
When Behavior Designer loads the external behavior tree it is making a copy of those nodes so other trees can reuse the same external tree. You can create the nodes at runtime though but this will not serialize:


Does that help?
 
When Behavior Designer loads the external behavior tree it is making a copy of those nodes so other trees can reuse the same external tree. You can create the nodes at runtime though but this will not serialize:


Does that help?
Oh Thanks! I'm sorry if I didn't make myself clear, I mean can I still use the BehaviorTreeEditor at runtime and change the external tree .asset file? We don't need use code to build a tree at runtime yet, and we also don't need change those copied trees. Now it seems that the "add/remove node function" of the editor is disbaled when game is playing.

1578326131548.png

Just like the image above, two cube has copy the externalTree at runtime, and now we want to edit the "ExternalTree - Behavior (external)" use the editor at runtime but the add/remove function is blocked. And Ideally we would like it can still save the changes to override "ExternalTree.asset".
 
Just so I'm understanding, if you are able to modify the external tree while the game is playing then that'll fit your use case? That should be possible, but this will not allow you to add/remove nodes from the live tree that is currently running. Does that work? If so I can get it in the next update which will be released soon to go along with Unity 2019.3.
 
Just so I'm understanding, if you are able to modify the external tree while the game is playing then that'll fit your use case? That should be possible, but this will not allow you to add/remove nodes from the live tree that is currently running. Does that work? If so I can get it in the next update which will be released soon to go along with Unity 2019.3.
Yes!! That would be perfect, we just need to modify the external tree while the game is playing. Thanks!!!

By the way, does the next update supprt Unity 2017.4.18f1?
 
Last edited:
Yes, it does. It'll likely be one of the last updates that supports 2017.4 though.
OK, does the new feature includes
1. Add variables For external tree
2. Add/Remove nodes
3. All ohter we can do to make changes to external tree with the bahavior tree editor when the game is not playing
 
Top