Download

Too many booleans for an animation

So, I want to play an AnimationMontage when sprinting (Action Mapping), but I only want to play it when the character is not doing anything else.

Right now I’m doing it with a lot of booleans, but I think it’s very inefficient.
Is there any other way to do this better?

Note: I’m a beginner

For lots of booleans you can create an enum. It’s basically a list of booleans. Then run a switch off it. This will allow you to set the logic flow for each boolean and all you need to do is set the enum for the logic pathway.

So for your system you could create an enum E_PlayerState or something similar. Fill in the list with each of your booleans. Then create a variable in your blueprint, set it to the enum. Grab that variable and drag the pin, type in switch, hook it up to your event then set up what you want to happen for each logic pathway.

After that go through your code and replace your set booleans with the enum set properly. You may need to do a bit extra to stop redundant actions or to combine multiple states.

There are other ways to do this, but I find it works well just double check that it is functioning as intended and modify bits to make sure it always does what you want.

EDIT: Noticed you are using this with input actions. So what you can do is create a custom event that takes input from your enum and run a switch off that. Then on each input action you can have it set the state to feed into your custom event to find the logic then on release you can set the state back to the prior and it will still work.

Hope this helps, good luck. If you are still having trouble post again with your code setup and we can get it sorted

A custom State Machine might help you with all the bools.

Also, you can use the Add pin:

Create a “Can I Sprint” function. Output a bool to branch.

Use enum switch and Selects to tidy up.

1 Like

I had the exact same problem and I solved it with an enum instead of bools like it was suggested and I also use CanThis, CanThat. If conditions change I only need to alter CanThis and CanThat.

Also:
I had never noticed the “add pin” on the “and”. hahaha