Is there some kind of isStateActive check?

Simon Keating 2 years ago updated by Lazlo Bonin (Lead Developer) 2 years ago 3

Obviously this would be really useful rather than having create/activate and deactivate additional boolean variables whenever a state is entered or exited. Does it already exist? Thanks

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):
Satisfaction mark by Simon Keating 2 years ago

Not at the moment. Specifying which state you'd be referring to is not trivial. In terms of UX, there's no easy unique identifier for a state in Bolt.

I'm guessing this isn't in any any of the latest updates yet? Might it ever happen? I actually found this to be quite a serious reason not to use bolt. Having to have an extra layer of bools for detecting if a state is active just made a ton of extra complexity to my already spaghetti code.

There has not been any update to include that feature yet, and I'm not sure it will ever be there. The reason is that it's very hard to refer to a state because it is a language construct (e.g. which state are you checking?). States do not have runtime accessible IDs and might be even inlined when generating C# code in Bolt 2.

Instead of using a bunch of booleans, why don't you use a single string object variable, e.g. activeState? When entering states on machines that you need to watch, you could set the value to an ID of your choice.

To make this even simpler, you could create two super units:

  • Identify State: 
    On Enter State > Set activeState to (string parameter),
    On Exit State > Set activeState to null
  • Is State Active: Compare activeState to (string parameter), return bool

With those, it should be pretty easy to implement your check!