How to modify different floats in a structure depending on the value of an enum?

Hello,

I have a structure variable containing a large number of different floats which represent the stats of my player character. I have an enum that states which stat I would like to modify and a float value of how much I would like to modify that stat by.

My question is how can I modify a different stat in my structure depending on the value of the enum, without using a switch statement to duplicate the same stat changing code over and over.

Attached below is an image of my current solution to change the stat, however my issue is that in order to have the changed stat switch based on the enum, I would need to duplicate these blueprints a great many times.

Is there a better way of doing this? Thank you.

I’d suggest keeping the stats in a Map(Enum, Float) instead of as individual floats. Something like this (I used some random UE enum as an example):

Note that you have to “re-add” the entry to update it because the “find” returns a copy, and not a reference. But that’s still fairly simple as you can see in the image.
If you need/want verification whether the stat exists, just use the red boolean wire coming out of Find. If you just fill the map with initial stat values when the game starts though, you don’t have to check anything.

Finally, either put this map into your struct or just remove the struct and use the map instead (if the struct only had stats).

1 Like

This is exactly what I was looking for, thank you.

1 Like

make sure you use SetMembersInStruct too, you dont have to link all the variables like that