Parallel States 2.3+¶
Parallel states work by allowing transitions to continue to evaluate in their sequence even after a successful one was found. Only after the sequence has finished and one or more transitions were taken will the previous state exit.
This is all performed on a single thread, and the order of transition evaluation is still based on their priority.
Conduits
do not support outgoing parallel transitions.
Video¶
Multiple Entry Points¶
Select an entry point to an FSM and choose Allow Parallel Entry States
. When dragging out from the entry point multiple connections can be created. Deselecting this option will clear all but one entry point connection.
Mark a Transiton to Run Parallel¶
Select a transition and click Run Parallel
. The transition will now display as two lines instead of one. If this transition evaluates to true or false the next transition in the evaluation sequence will still evaluate.
Mark a State to Default to Parallel¶
Select a state and toggle Default to Parallel
. This will convert any existing transitions from this state to run either parallel or singular. Any new transitions dragged out from the state will default to this behavior.
Leave States Active¶
It may be desired for a state to continue to remain active even when a transition out was successfully taken.
Configure a State to Remain Active¶
Select Stay Active on State Change
from a state. When a transition is taken from this state the state will no longer exit and OnStateEnd
will not be called.
Merging Active States¶
When active state A enters active state B, the default behavior is just to run OnStateEnd
for state A with state B not being affected.
State Reentry Behavior¶
If Allow Parallel Reentry
is selected on state B, then after OnStateEnd
of state A is called, OnStateBegin
of state B will be called again. OnStateEnd
of state B will still never be called until state B fully exits.
Transition Evaluation Optimization¶
Deselect Eval if Next State Active
from a transition if you do not want it to evaluate when between two active states. Without this selected it is not possible to merge the two active states or reenter the next state.
Manually Activating States¶
Individual state nodes can now be manually made active or not.
SetActive(bool)¶
From a state node call SetActive. This will add or remove the state to or from the current active states of the FSM.
This method is replicated.
End State Behavior¶
When any parallel state reaches an end state the owning FSM will be considered in an end state.
Implementation and Best Practices¶
Parallel states are designed be open ended for your own implementation. You can configure your own state and transition classes to better assist with parallel behavior. For example, you may want a state to remain active, but any transitions out to only be taken once. You can create a transition class with its own boolean which gets set to true On Transition Entered
. Then configure the transition condition to not take it if it's already been taken once.
If you mark transitions to run in parallel it might be a good idea for the transition logic to either default to true, or have conditions that can be determined within a single tick. For example, you have three transitions out, but only two are true. Two next states will become active, but the current state will exit so the third transition won't evaluate again. If you want the third transition to eventually be taken one solution in this scenario would be to have the state remain active and configure the transitions out to only be taken once (or only allowed to be taken again if the previous state is reentered).