In State Tree, we have a situation where we would like to pass some data along with a state tree transition, from sibling state to sibling state. That is, State A is transitioning to State B, and there is a parameter that we would like to pass from A to B.
What is the preferred method for doing something like this?
You can use StateTree events with a payload to send data between states. The state being entered would need to have the Required Event to Enter flag enabled with the expected payload struct defined. You can then bind properties in tasks/conditions/etc. to data from the payload struct. If it is data that is needed at certain times but not always when entering the State B (assuming it is not coming from State A), you can add parameters to a shared parent state or use the parameters of the tree. You can write back into those parameters using FStateTreePropertyRef or in 5.7, you can now bind output values to those parameters to write the data from the task into a parameter.
-James
Yes. This allows for a payload to be sent with the transition. If you wish to have the task complete without the event, you could investigate using a parameter at a point in the tree to store the payload you would want to use. The only issue with that approach is that other tasks can change the data in that parameter before the other dependent task copies it.
-James
Ah, so in this case, instead of having a Task mark itself complete, it would send an event to the whole State Tree to cause the transition? That makes sense.