Get/set Object component with BD

DXWarlock

New member
Perhaps I am just missing the documentation, or the task that can do such a thing.

I have a component script that stores floats for such things as health/hunger/mate status etc, on the same GameObject as the behavior tree. But I cannot find a way for a behavior to read nor update those variables.
For example I have been playing with how to do a simple behavior of tasks for hunger: Wander, if can see food, check hunger, if hungry, move to, destroy food object, set hunger to 0.

Works fine without accounting for hunger, it wanders, sees food goes and destroys the food GameObject. But I cannot for the life of me, short of making a custom task, figure out how to read or update 'hunger' on the same GameObject the Behavior Tree is on. I have attempted to use every reflection that seems applicable, but none expose that variable to read/write to on the GameObject.
 
Last edited:
You can use GetComponent like regular MonoBehaviour and then access your variable. For example:

Code:
var hunger = GetComponent<MyStats>().hunger;
 
Top