# State Tree variables

**URL:** <https://forums.unrealengine.com/t/state-tree-variables/728739>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, state-machines, Blueprint, CPP, question\
**Created:** [December 15, 2022, 6:38am UTC](https://forums.unrealengine.com/t/state-tree-variables/728739 "2022-12-15T06:38:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pete\_the\_B](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pete\_the\_B](https://forums.unrealengine.com/u/Pete_the_B)\
**Post date:** [December 15, 2022, 6:38am UTC](https://forums.unrealengine.com/t/state-tree-variables/728739/1 "2022-12-15T06:38:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Light\_Shock](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/light_shock/32/1194530_2.png) [@Light\_Shock](https://forums.unrealengine.com/u/Light_Shock)\
**Post date:** [December 20, 2022, 9:08pm UTC](https://forums.unrealengine.com/t/state-tree-variables/728739/3 "2022-12-20T21:08:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pete\_the\_B](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pete\_the\_B](https://forums.unrealengine.com/u/Pete_the_B)\
**Post date:** [December 21, 2022, 6:12am UTC](https://forums.unrealengine.com/t/state-tree-variables/728739/4 "2022-12-21T06:12:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Light\_Shock](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/light_shock/32/1194530_2.png) [@Light\_Shock](https://forums.unrealengine.com/u/Light_Shock)\
**Post date:** [January 4, 2023, 8:13pm UTC](https://forums.unrealengine.com/t/state-tree-variables/728739/5 "2023-01-04T20:13:40Z")

</div>

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.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/b/5/eb52665b3c54fa012b6728175cb5a72fe049beb0.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/3/d/53dc52a110f4cee6a6a66ac62dcb46ced3bc359e.png)  
In the above example if the skill check passes then the Successful approach tag is set.

---

<div class="post-metadata">

**Author:** ![Anonymous\_cd45bd7fa50f0ba0cf8a540613f93d6e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_cd45bd7fa50f0ba0cf8a540613f93d6e](https://forums.unrealengine.com/u/Anonymous_cd45bd7fa50f0ba0cf8a540613f93d6e)\
**Post date:** [August 2, 2023, 9:16pm UTC](https://forums.unrealengine.com/t/state-tree-variables/728739/6 "2023-08-02T21:16:59Z")

</div>

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

> [@How to assign StateTree parameters at runtime](https://forums.unrealengine.com/t/how-to-assign-statetree-parameters-at-runtime/721953/5):
>
> As far as I know, parameters are “set once, read only” data. If you want runtime parameters, you have to Make a task, global task or evaluator where the variable will be calculated. Make your variable in this object. Make it instance editable (click on the eye), or in C++ make it VisibleAnywhere or EditAnywhere (I believe either should work) Move it to the Output category. It must be spelled correctly, it won’t work otherwise. Add the task or evaluator object to the tree. If you did everything…

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.
