Variable Syncing with subtrees

..Tom..

New member
I'm using an external behavior tree to replicate a sequence of tasks I am repeating at multiple places throughout my tree.

The tree has a number of variables from the parent tree it needs to know about. Things like NavMeshAgent speed, angular speed, destination, etc. but also others.

It works if I pass them as parameters. But as I said, I'm using this reference in multiple places and I want to avoid that I forget passing one variable here or there and it'll be hell to debug.

Is there a way for an external behavior tree to simply inherit or access all of the variables that the tree it's referenced from uses? Or some other trick that I'm missing?
 
Am I using the wrong thing, maybe? I am using Tree References so far. I see the "Start Behavior Tree" Task has a "synchronize variables" option. Should I be using that instead?
 
Even if you don't specify the variables on the Behavior Tree Reference task the subtree will still inherit the variables from the parent tree. By specifying a variable on the actual reference task you are able to specify a unique value for that specific subtree. If you're wanting to ensure the variable stays in sync with a property on the component (such as navmesh speed) then you can use property mappings (on the bottom of this page): https://opsive.com/support/documentation/behavior-designer/variables/
 
It doesn't inherit anything in my case, possibly because both behavior trees are external behavior trees. Thus the subtree actually knows nothing about the parent tree, it seems.

At least in the editor, I cannot use those variables and they don't appear in any dropdown menus on Tasks.
 
Ah, at edit time you are correct in that the variables are not passed down. There isn't a way to have it automatically pull in all of the variables from another tree either. They are pulled in at runtime though.
 
Got it. So if I were to put there "Dynamic" and use the name of the parent tree, it should work as long as I don't reference the subtree from a parent tree that doesn't have these variables, right?
 
Also, why isn't there? Can't you inspect all external trees and check for references? Performance etc. might make it impractical, but in theory?
 
I'm not completely following but if there's a variable with the same name/type from a parent tree then that variable will be inherited to the subtree at runtime. If that variable is named something different then it will not be used by the subtree.
 
I think I'm lost a bit as well. :)

So, to inherit variables - do I have to define the variable in the subtree and then its value is automatically set, or do I not have to define it and the whole variable, including types, values, name is inherited?
 
Any variable that is defined in the parent tree will be passed down to the subtree. If the subtree has the same variable name and type as the parent tree then that variable will be the same between trees.

For example:

Tree1: VariableNameA, int. VariableNameB, float
Tree2: VaraibleNameC, int, VariableNameB, float

When Tree2 loads as a subtree it will have three variables:

VariableNameA, int. VariableNameB, float. VariableNameC, int.
 
Top