Am I Understanding Enums Correctly?


I currently have a couple of projects which are filling up with boolean variables and I was wondering If I can replace these with Enums?

For example, I have a character that can cast different spells, each with a booleon value set to true or false if in a ‘casting’ state. Each casting state has different animations assigned to it and the BP graph and anim BP’s are starting to get a bit messy.

If I create a Enum with a list of all the different casting states can I then collapse my individual ‘spells’ codes to functions. Then my character blueprint could be simplified to 'if input action 1 is pressed, set enum to ‘magic ability one’ which could then trigger the desired function and switch back when completed?

Example 1:

I also am working on some parkour movement on a seperate project where it would be really useful to link various values to my enum so that they can be called easily in an animation statemachine / potentially better option I don’t yet know about.

If so, is there any way of checking if an enum is active in a animation blueprint and then playing the corresponding animation? This could really clear up my state machine and allow for more complex / additional transitions.

Ideally I could then have Idle -> Walking/Running -> ParkourMovement rather than what will quickly turn into a mess in my example:

I’ve tried looking for solutions online but the basic enum tutorials just show you how to create a list, rather than assigning specific values (such as a booleon) to the items on the list. I’m sure there’s a better solution than what I’m doing but don’t really know what to look for.

Thanks in advance for any help.

Well enum are just a tool, i think that is just make things “more readable”
lets say you have 14 spells in order and you use "a int " to call the spell you could go creazy in no time !
cast spell 1, if spell 1 hit spell 7 = reduce damage…
With enum
Cast spell fireball, if fireball hit fireshield = reduce damage

Well, yes you can use enums for work like booleans,
for example if you have 2 magic actions, you can just set the Action1 to Spellfire and action2 to Teleport when their animation ends, the slot can be set back to “nothing”

If you have more complex thing like “magicka” where you can merge a number of magic type in one spells
you can have a list of magictype in your enum and fill an array of enum with the “whole spell”

If you have a boolean for every spell you can cast you can also, use just 1 boolean for that and store what spell in another variable .
For example, 1 int and 1 bool
Spell_Selected=8 (the spell is selected and is the “firewall”)
Bool_0 (the spell is waiting to be casted)
Bool_1 (you are casting the spell)
Well, at this point i would like to add a cooldown or more stuff so , i dont feel very comfy with this way.
For Example 2 Enumerator
Spell_seleceed = SummonThunder (or Fireball , Firewall, Firesword, Firestorm, Firebeam…)
Spell_State= Cooldown ( or Ready, Castingsingle,Mutlicasting ,Focusing, Deactivated… ChargedBeam… )

Animations and timing and targets and stuff should be saved in safe place and referenced only,
I dont thinik you want to check the animation and the distance and the effect to spawn every time you want to castthe spell.
You want only to say , player will start casting the FireBlast, so get the animation and effects and stuff of that spell from a “database”
There are some cool way to store data take a look at structures!

Yes exactly , like in the example i made before , right?

You can create a “Switch on Enum” to run different part of the graph basedd on the enum,
BUT you can also create a “structure” that you can fill with all the data like
“Fireball” - Animation:Evocation_N2 … time_casting:1sec … Spawn_effect:Sparkles …Time_cooldown:1sec…
And you can create an event or function in wich pin in the Fireball and all the other variables will be inside.

I dont know :stuck_out_tongue:

The enumerator are just a " set of constant names " or something like that,
Enumerators are just a list of keywords
you cant have booleans inside, or add specific value other than the keywords themself.

Maybe what you want to explore are structures
in wich you can add more variables and create a structure for spells like i mentioned before