2
\$\begingroup\$

This question refers to the use of enhanced input in Unreal Engine 5. Whenever I say "modifier", I refer to modifier keys such as Shift, Alt, and Ctrl (rather than the Input Modifers such as Dead Zone and Aim Assist).

I am trying to bind actions to mouse and keyboard inputs that require the user to hold a modifier key, e.g. the following ones, which one would typically find in RTS type games:

  • Left click without modifiers to select a unit
  • Left click + Shift to add to selection
  • Keyboard key 1 to select the units in control group #1
  • 1 + Ctrl to define control group #1
  • 1 + Shift to add to control group #1

This can be easily achieved through the deprecated Action Mapping in the Project Settings:

Deprecated action mapping

However, I am looking for a way to achieve the same through the preferred Enhanced Input Actions and Input Mapping Context. How does that work?

I could probably achieve the desired outcome with a Chorded Action (by defining a helper action for "Shift is Down" and then adding it as Chord Action to the left click. However, not only would I need to do this with the modifier I want, I would even need to add Chord Actions for those I don't want: otherwise if shift is down, both "Left click+shift" and "Only left click" will fire. That sounds insane. What am I missing (and why don't I find this in the docs -- this seems like a common use case)?

\$\endgroup\$
1

1 Answer 1

4
\$\begingroup\$

After doing some more research and implementing a solution that does work for me, I feel confident to be able to answer my own question. Unfortunately, the answer is: It's as cumbersome as already outlined in the question.

  • Create Input Actions for Shift, Alt, and Control, and a dedicated Input Mapping that maps the respective left and right keys to these Input Actions. No special Trigger is needed for that.

    Mappings window screenshot

    These platform specific actions actually defeat the purpose of the entire approach, but it gets the job done.

  • Always have this Input Mapping added to the Enhanced Input Local Player Subsystem with a sufficiently high priority.

  • Create a second input mapping that holds your actual actions. For each action that requires a modifier key, use a Chorded Action, and use the Input Actions created above as the Chord Action.

    Input action with modifiers

  • Note that the question contains an unnecessary assumption: It is not necessary to enforce absence of a modifier key for the action that doesn't require one. For some reason, the more specific action (the one that does specify a Chorded Action) takes precedence over the general one, but I found no documentation about how this works precisely. This makes it a bit less cumbersome than suggested in the question.

An almost identical solution has been posted in the UE Forums and repeated in February 2023, so there's likely no better solution possible at the moment. If a better option will be made available in a future version of Unreal Engine, please post another answer and I'll mark that one as correct.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .