Hi, I’m trying to use State Trees in 5.1, but I noticed it’s not possible to add variables to a tree. The documentation is quite limited for State Trees and I’m trying to figure out how to add something as simple as a float, which can be modified by tasks. Does anyone know how to add state variables?
Did you get any further with this - I have been working on it and thought the binding functionality would do it but changes do not seem to be being reflected back into the owning actor.
I worked around the problem. Some state is kept in tasks themselves and some in the context actor. I would prefer to keep it in the tree itself, but don’t see how.
An update for people who find this thread. What I’ve found to be the best approach is to expose a variable in the owning actor and then in your state tree tasks to set this variable by referencing the actor though context.
In the above example if the skill check passes then the Successful approach tag is set.
I am replying to this old post because it’s one of the first replies that come up in Google, and it seems nobody else has posted how to do this. I explained how to get runtime variables in state trees step by step here
The tl;dr is that if you bind to a variable you’re reading from it. In order to write to a global variable that other tasks and evaluators can read, you need to make the variable you want inside a task/evaluator and set it to the Output category. Then you will be able to change it (but only from that specific object), and other tasks will be able to read it.