x157 / x157.github.io

46 stars 7 forks source link

Bug Fix: How to Fix EnhancedInput WASD Keyboard Input in Lyra 5.0 and 5.1 #15

Open x157 opened 1 year ago

x157 commented 1 year ago

Problem: In Lyra and Third Person Template for UE 5.0+ the WASD keys on the keyboard to not work as expected. Pushing multiple keys in particular is broken. W+S keys should cancel out. A+D should cancel out. By default the examples Epic provides for IA_Move do not work this way and it feels broken.

Solution: for Keyboard Only, delete the keyboard IA_Move triggers, and add 4 different input actions IA_MoveForward, IA_MoveBackward, IA_MoveLeft, IA_MoveRight, which are mapped to your WASD keys instead of all 4 going to IA_Move.

With such a setup, pushing all 4 keys simultaneously will result in zero movement.

NOTE: I believe Epic may be looking to fix this, possibly as early as 5.2. If you need to fix this yourself in 5.1 or 5.2, here is the procedure:

Input Mapping Context:

image

Input Action Map:

image

Make sure for each one you copy, to copy the same settings as you see in IA_Move for this key.

image

Also copy the settings for the "player mappable" slot:

image

I just sent all of the new input tags to the same function that is handling IA_Move. In Lyra it's called Input_Move.

(In vanilla Lyra you'll want to edit ULyraHeroComponent::InitializePlayerInput. I derived a custom UXCLPlayerInputComponent based on ULyraHeroComponent).

image

For details on the LyraGameplayTags hacks made, see this comment (below) courtesy of @WhyAreLess

Also note: The above screenshot was using Lyra 5.1 style tags. After updating to Lyra 5.2 style Tags, the code looks slightly different, but the fix is essentially the same.

Files changed for fix:

image

I know, I know... I shouldn't hack LyraGameplayTags.cpp... I know. 🤣

ghost commented 1 year ago

For anyone having their character(s) stuck, don't forget to add the gameplay tags to the LyraGameplayTags.h image

and LyraGameplayTags.cpp aswell. image

x157 commented 1 year ago

Changed this to Bug Fix as I believe Epic will fix this hopefully in 5.2. Thus no how to fix tutorial will be needed after 5.2.

eXifreXi commented 1 year ago

fyi for those who come here in general, not only for Lyra. 5.2's code still has the same "bug". I believe this is intentional and one isn't supposed to use 1 InputAction_Move for WASD (it does work for 1 Left Thumbstick Axis of a Gamepad though, just not for 4 keys WASD). So the bug is basically in Lyra not in UE.

x157 commented 1 year ago

Thanks @eXifreXi. I agree, I think the C++ EI implementation is designed to work that way and isn't bugged.

What is bugged is just the input configs used in Lyra (and the 3rd person template, and perhaps also other samples/templates/etc). Still bugged in 5.2, as you say. Fingers crossed they fix the configs for 5.3!

DexArson commented 1 year ago

In UE5.2, the Enhanced Input keyboard input still doesn't allow two opposite axes to cancel each other out. And I've tried your method, it's quite strange that if I hold down the WS keys first and then hold down the AD keys, the character can stop properly. But if I press the AD keys first and then press the WS keys, the character will move forward or backward (depending on whether W or S was pressed first).