# Switch on Structure?

**URL:** <https://forums.unrealengine.com/t/switch-on-structure/1332151>\
**Category:** Programming & Scripting\
**Tags:** Struct, Switch, unreal-engine, Blueprint, question\
**Created:** [October 14, 2023, 10:08am UTC](https://forums.unrealengine.com/t/switch-on-structure/1332151 "2023-10-14T10:08:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TorQueMoD](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/torquemod/32/710746_2.png) [@TorQueMoD](https://forums.unrealengine.com/u/TorQueMoD)\
**Post date:** [October 14, 2023, 10:08am UTC](https://forums.unrealengine.com/t/switch-on-structure/1332151/1 "2023-10-14T10:08:09Z")

</div>

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/c/0/0c0f22aed9bb46599e33445e38bb32c7ee6db0f0.png)

---

<div class="post-metadata">

**Author:** ![Auran131](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Auran131](https://forums.unrealengine.com/u/Auran131)\
**Post date:** [October 15, 2023, 1:43am UTC](https://forums.unrealengine.com/t/switch-on-structure/1332151/2 "2023-10-15T01:43:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [October 15, 2023, 1:54am UTC](https://forums.unrealengine.com/t/switch-on-structure/1332151/3 "2023-10-15T01:54:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TorQueMoD](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/torquemod/32/710746_2.png) [@TorQueMoD](https://forums.unrealengine.com/u/TorQueMoD)\
**Post date:** [October 16, 2023, 11:09am UTC](https://forums.unrealengine.com/t/switch-on-structure/1332151/4 "2023-10-16T11:09:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TorQueMoD](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/torquemod/32/710746_2.png) [@TorQueMoD](https://forums.unrealengine.com/u/TorQueMoD)\
**Post date:** [October 16, 2023, 11:10am UTC](https://forums.unrealengine.com/t/switch-on-structure/1332151/5 "2023-10-16T11:10:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [October 16, 2023, 12:00pm UTC](https://forums.unrealengine.com/t/switch-on-structure/1332151/6 "2023-10-16T12:00:56Z")

</div>

> [@TorQueMoD](#):
>
> Unless a Key is a type of Struct? I don’t think they are.

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

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/e/5/de5265f209d65b4ca38e4f9ad526cabdd9ce2f3d.png)

`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.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/4/b/34b495fafa88ceacfa870539e33682da772ecd1d.png)

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

> [@Enhanced Input System misunderstandings.](https://forums.unrealengine.com/t/enhanced-input-system-misunderstandings/1312554/5):
>
> Now tested (and rather obvious once pointed out!):

---

<div class="post-metadata">

**Author:** ![TorQueMoD](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/torquemod/32/710746_2.png) [@TorQueMoD](https://forums.unrealengine.com/u/TorQueMoD)\
**Post date:** [October 22, 2023, 8:06pm UTC](https://forums.unrealengine.com/t/switch-on-structure/1332151/7 "2023-10-22T20:06:12Z")

</div>

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