Gamepad Axis Events are Dirty Little Liars

I am trying to support both mouse/keyboard and gamepad for a twin-stick-shooter style game. I’m scratching my head at gamepad axis events and how deceiving they are.

My axis events are mapped like so:

With my gamepads disconnected I receive gamepad axis events with a value of 0.0f every frame. With no gamepads connected, I’d expect this to either not get called or be NaN. I feel like I’m missing a key part of this story, do people dynamically bind/unbind axis based on gamepad connection polling?

0.0f events are received every frame no matter which input device you are using. You should use something like this

if (!FMath::IsNearlyEqual(Val, 0.f))

Right. I’m doing some outright gamepad detection now:

if (UseGamepad)
    LastAimX = Val;

I guess I’m more interested in why this is the case from an architectural point of view. 0.0f is a valid axis value for a gamepad but that’s if and only if your gamepad is connected.

I don’t know if this has any bearing on your case, but I think you are only supposed to make one map pr. axis. The positive one, that is. Now, I would imagine, that the inputs would report both 1 and -1 and -1 and 1, depending on which way you go on the axis…

Thanks for mentioning that. It doesn’t affect the original issue, but it does make things cleaner and that makes me happy :smiley: