2 dimensional dictionary

I’m working on a top down shooter and I’m coming in a bit of a struggle right now.

My animation flipbooks are divided into lower body (idle, walking, running, strafing) and upper body (idle, moving, shooting, etc.).

I have an Enumeration for the MovementState (idle, walking, running) and another one for the EquipmentState (which weapon currently is equipped).

The lower body doesn’t cause any problems, but the upper body animation is dependent on both the Movement and the Equipment. When I start/stop shooting, I have to select idle/shooting plus dependent on which weapon I am holding… This slowly becomes a load of flipbooks (and branches) as I have 3 different animations for each of the #insert_number# different weapons.

So I thought I could use dictionaries for this sort of thing and it seems pretty convenient to me… simple key-value pairs, you’d feed it your current EquipmentState and get the associated animation flipbook.

But now I’d need this as a table, one Key would be the EquipmentState, the other one would be the MovementState (in order to switch back to idle when I stop shooting or whatever). Basically like a table, every row is a different weapon, every column a different MovementState… Is that possible?

Or do you know of any other way for doing something like this?

Thanks in advance!

PS - other thoughts on solving this:

  • I could add in one dictionary for each weapon there is to equip (EquipmentState enum, Flipbook ref) and select the appropriate dictionary using a switch on MovementState (but that would lead to, like, 13 different dictionaries in my Character BP)
  • I tried making the UpperBody a ChildActorComponent and making every Weapon a different Actor, all derived from a parent class UpperBody, so I always call the same functions (shoot, move, whatever) but I can feed it different flipbooks… (which again leaves me with, like, 13 different Actors for all my equipment…)
  • I read about DataTables, but those are only for base values, not for Flipbook (or other) references, are they?

Isn’t there anyone who got some advice? Duh…

You can use a variable Map for this - check out this short vid: https://www.youtube.com/watch?v=cf25ekO-AFs&t=1s

Yes, I know. They’re also called dictionary, but that’s basically what I’m talking about. I can use an enum as a key and get the reference to the corresponding Flipbook, but what I need is a dictionary that takes 2 keys (2 different enums), like it’s 2 dimensional, basically making it a table.

That way I could say something like FlipbookMap → get Flipbook (currentEqupimentState, currentMovementState)… I guess I’ll just have to stick to making an UpperBody Actor for each equipment…

I see, well you might be able to use a data table with the first key as the row name and then the second key as a field in the struct. This means you will have a few repeated values but it might work.

Look at structs and data tables - this might help!