Im new to Unreal Engine. For now i cant wrap my head around input system. I want to make switch items system with number keys(0-9). Do I really have to create different IA for every key? Or i can put all keys i need in IA and somehow get each pressed key from input event in graph? Because i dont see that keys in enhanced input system can return values vider than -1 to 1 in my case. As always, sorry if it sounds stupid.
I am going to sound stupid with you, hold my blueprint…
- if this is the IA:
- and this is my context:
- must I really go full loopy spaghetti and:
To get the Key
that triggered it? This is not even the full thing, you’d need to add exception handling here.
Why can’t we have nice things and have the key struct returned here?
There might be a good reason (or a proper way!), asking for a friend.
That’s exactly what i meant. That loopy stuff looks terrible.
Incorrect answer#1
upd: not the first time i confuse a nice custom feature in my project with default one. The content of answer#1 was about a custom solution made to pass a custom params along with action based on mapping settings. So, basically, move EnhancedInput
to your project and extend it as you like it.
In InputMapping there is a field ActionParam
, where you select a class derived from UInputCustomParam
. And here you can attach custom parameter for each individual binding of particular InputAction.
Like:
[Key:1][IA_SelectItemSlot][ActionParam:MyInteger=1]
[Key:2][IA_SelectItemSlot][ActionParam:MyInteger=2]
Then you bind IA handler, that receives const FInputActionInstance& ActionInstance
as param and from here you can do
auto Params = Cast<UMyCustomParam>(ActionInstance.GetCustomParamValue()))
int ButtonIndex = Params->MyInteger;
Not sure it’s available from BPs as is, but you can always wrap it for your needs.
That’s would be the most generic way of doing it.
Correct answer#2:
[not tested] But if you need just an int\float value, instead of ActionParam
you likely can, in a same way, for each binding in InputMapping
, just add a modifier Scalar
, that will scale resulting value of your input.
Like:
[IA_SelectItemSlot=1D float value]
[Key:1][IA_SelectItemSlot][Modifiers:Scalar=1]
[Key:2][IA_SelectItemSlot][Modifiers:Scalar=2]
upd2: that’s okayish solution for discrete buttons, but it will fail on gamepad triggers if you assume them as such. So, applicability of this method is limited
Thank you all very much. Saved a lot of my time.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.