Switch on Structure?

I’ve created a structure of different keys and I want to be able to switch on the different values, but apparently, there isn’t a switch on struct.
How do you work with structs in this way?
SwitchOnStruct

if they cant be converted to enums or tags or something then you’ll just have to loop over all structs and break when you get a match

It looks like the gamepad buttons are, in turn, each a struct. If that is the case, you’ll need to also break those structs, because you get something you can switch on.
If they are just scalar values, you should be able to drag a link out of “A” and do a “switch” on that. But if it’s a float, then you can’t “switch” on a float, because those have millions of possible values – you’ll have to first use a “greater than” comparison node to compare to whatever your threshold is.

Or maybe I don’t understand what it is you want. If you try to switch on “if key A is down, then … else if key B is down …” then that’s not a switch, because what if both buttons are down? To do that kind of logic, you’ll need a series of conditions / if statements.

Also, for decoding input, I highly recommend using the built-in support in the enhanced input component/system. It does a lot for you, and gives you things like “player mappable controls” for almost-free.

No, they’re Keys. They are the same color as a struct though, so that’s confusing :stuck_out_tongue:
Unless a Key is a type of Struct? I don’t think they are.

But then how do I determine when I want it to break? I want the same behavior as Switch on Enum where it does something different depending on which one is being used. I won’t know which one is being used beforehand.

It is. Would something like this work in this case:

Key | Enum could work even better - be more descriptive.


Hard to tell where the input is coming from here but the Enhanced Input system handles it already.

Alternatively, you can have a scalar modify Action Values to evoke specific behaviours:

That definitely looks like it might work. I’m using 4.27, but at the very least the switch on Int should help. Thanks!