External Tree Runtime

Ell223

New member
Hello,

I am trying to setup a system where a different external tree is run on a BehaviorTreeReference node, dependant on some variables set on the GameObject containing the tree.

Essentially I have a character who needs to perform their "job task" at the same point in the tree, but these tasks can be different (e.g transport goods, chop down tree), and I need to set the shared variables for this external tree before it runs, however I'm not quite sure how I should set this up. How am I able to change the referenced behavior at runtime? And how do I change the variables for them.

I have it set up currently just always running the same external tree, but I can't set the variables for it. How is this done?

Thanks,
Elliott
 
For this situation you can inherit the BehaviorTreeReference task and then override the GetExternalBehaviors method. When the tree loads GetExternalBehaviors is called and returns the external tree that should be loaded. You can determine at runtime which external tree should be loaded at that time.
 
Thanks. So does this mean, after the tree is loaded, that reference cannot be changed? So for example, if the character changed job (e.g wood cutter, to baker, or similar) during the game, they would need to reload their tree with the changed reference (representing their new set of tasks for that in-game job)?
 
Thanks. So does this mean, after the tree is loaded, that reference cannot be changed? So for example, if the character changed job (e.g wood cutter, to baker, or similar) during the game, they would need to reload their tree with the changed reference (representing their new set of tasks for that in-game job)?
That's correct - when the tree loads the Behavior Tree Reference is consumed by the external tree so in order to get it back you need to reload the tree. Way one to do this would be to have a separate external tree that acts as your main tree, and you load this external tree initially (which contains the behavior tree reference task). After you decide that you want to change trees, you can load this original external tree again (that still contains the behavior tree reference task) and again determine which external tree the reference task should load.
 
Hello, Justin.
I have a behavior tree as shown in the image below.
Of the 6 trees selected in the red box, only one of them is actually used in the game.
I don't want this tree to load these 6 subtrees at runtime. I only want to load the subtree that is actually used. How can I do that?

Thanks!


WechatIMG127.png
 
For this situation you can inherit the BehaviorTreeReference task and then override the GetExternalBehaviors method. When the tree loads GetExternalBehaviors is called and returns the external tree that should be loaded. You can determine at runtime which external tree should be loaded at that time.
Hello, I try inherit the BehaviorTreeReference task and then override the GetExternalBehaviors method.
But i have a question, I didn’t know which subtree should be loaded until the last task was finished.
How can I do that?
Thanks!
 
I didn’t know which subtree should be loaded until the last task was finished.
How can I do that?
You should load the behavior tree after you know which subtree will be loaded. This will allow you to use GetExternalBehaviors.
 
Top