Any State: Exit Previous State when entering New State

SrBilyon Harris 3 years ago updated by Bato 1 year ago 6


I'm currently looking to reduce the amount of transitions down for states that may have an entry point from various, and potentially, disconnected situations. My idea was to have a Custom trigger that would trigger a transition into a different state. Below is two examples. 

  • The first example displaying State A having a two way transition connection with State B and State C. 
  • The second example displays having State A having an entry transition into State B and State C, with the latter states calling a Custom trigger that fires the event in the transition for "Any State" to State A.

The Trigger is working, and I'm able to enter into State A, however, the previous state remains active as well.

Below is a partial example Use Case:

  • An actor could be "Grabbed" at any time. So once said actor is Grabbed, I would like to transition the actor into the Grabbed state via a Custom Trigger. This happens, but the previous state remains active as well. 

It would be nice to have an option that either:

- Force exit the current state when entering another state via "Any State"

- Having a unit that's explicitly for transitioning into another state that might not be connected via a transition, essentially, transitioning between detached network of states.

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):
Under Review

Thanks for submitting the idea.

Currently, the Any State unit exits only directly connected outgoing states.

The way I would like to rework this behavior is to have it exit all state in its "network", even if indirectly connected. This implies a tree traversal, but I can probably do it fast and without any memory allocation.

The built-in Mecanim state machines kinda sets the expected language in Unity.

There is an Entry state and an Exit State always. And the AnyState node quits current active state (allowing an override whatever the state was).

"Currently, the Any State unit exits only directly connected outgoing states.": Can you elaborate what this means? I was having this exact same issue and maybe this would solve it, where triggering a restart of the state machine would leave the last one still hanging on update (and it won't trigger an enter event if it gets back there).


In that example you show here, the proposed change would fix it.

When Any State would enxter _PROXY_, it would first make sure Start, WelcomeScreen and ActionPhase are all exited (it would be recursive). 

Currently, it only checks that _PROXY_ is exited (it is non-recursive).

We are actually going to include this change in the next Bolt 2 Alpha (2.0.0a3).


(Sorry for the bump/necro, I'm doing some roadmap grooming following the Unity acquisition!)

This is now supported in Bolt 2.


Will that ever be fixed in original Bolt? Bolt 2 is not officially coming out any time soon so we devs still use regular Bolt. It very annoying bug, why would anyone ever want previous state of state machine to remain active when it got changed? That defeats the whole purpose of statemachine. Hoping to see a fix soon.


I am using Bolt in unity and this annoying bug is still happening. My State Graph becomes much more complex because I need to make transitions from every single flows to Reset flow. Would be happy if the team can fix this issue.