How to pass arguments from composite to selected task?

caleidon

Member
I've implemented a composite called "JobChooser" which will assign a job (chop, mine, farm) to an agent.

It does so by checking the requirements and running the appropriate job, which looks like this:
Screenshot_1.png

The three jobs as seen above are references to external behavior trees that expand at the startup.

My problem is that I need to have dynamic variables passed to these jobs and I'm not sure what the best way is to do it.
I don't think I can use SharedVariables because I'd need to have ALL possible combinations of the required information (dozens, possibly hundreds) of shared variables defined in the "Job Chooser" so that they can get passed down to the individual tasks.

EXAMPLE: The "Chop" task gets chosen for execution. It requires two arguments - tree_position and tree_id. These two arguments become known in the Job Chooser's "CanExecute()" override, where it first checks if a job is possible, and if it is, it defines that that task will run next and needs to pass the arguments.

What's a good way of doing this?
 
If you have a lot of arguments one way would be to have them completely separate from the behavior tree and within your task you'd get them independently from a new component. For example:

Code:
int treeID = GetComponent<VariableManager>().TreeID;

From the behavior tree perspective any parent SharedVariable will automatically be passed down to the external tree at runtime. Within your external tree just make sure you have the same variable name and type in order to allow the value to be overridden.
 
If you have a lot of arguments one way would be to have them completely separate from the behavior tree and within your task you'd get them independently from a new component. For example:

Code:
int treeID = GetComponent<VariableManager>().TreeID;

From the behavior tree perspective any parent SharedVariable will automatically be passed down to the external tree at runtime. Within your external tree just make sure you have the same variable name and type in order to allow the value to be overridden.
The second way you mentioned (using SharedVariable) seems very impractical because I'd also be passing down SharedVariables for other jobs which aren't required. Is there any way to pass only 5 out of 100 SharedVariables to the external tree child that gets chosen for execution?

As for the first example, that does sound more feasable. However, could you please elaborate more on what a VariableManager is? Is it just a regular MonoBehavior with every single possible argument stored for every single possible job, and then jobs extract what is needed at runtime while the rest sits there unused?
 
Is there any way to pass only 5 out of 100 SharedVariables to the external tree child that gets chosen for execution?
No, all variables will be passed from the parent to the child tree.

Is it just a regular MonoBehavior with every single possible argument stored for every single possible job, and then jobs extract what is needed at runtime while the rest sits there unused?
Yes, that's correct. Depending on your structure you could have different MonoBehaviours which store different variables and then the MonoBehaviour that you call depends on the task that you are in.
 
Top