No mouse events are firing at all, and all Action.ReadValue()
calls return null. All other events for other devices such as keyboard and game-pads fire normally. When i look at the Input debugger
<Mouse>/Delta/x
and
<Mouse>/Delta/y
Are missing. Here is a picture of my ActionMap:
And here is the missing
<Mouse>/Delta/x
When game is running:
When using a gamepad, the device is actually visible in the input debugger like so:
using Mouse.Delta.x.ReadValue()
Does actually work in code, but is not a valid solution to my problem in a local co-op scenario.
INPUT PROBLEM FIXED! so, the issue was that ONLY mouse events were not being registered as noted in the thread. well, if i use the PlayerInput
Component (which I have been) on a GameObject
that was added in the editor during design-time, mouse events actually work, but, if you spawn a GameObject at runtime that has the PlayerInput
Component, THAT is when mouse events don’t work (which is what I was doing). So, this simple line of code fixed it:
GetComponent<PlayerInput>().enabled = false;
GetComponent<PlayerInput>().enabled = true;
disable and re-enable. Also, simply doing:
GetComponent<PlayerInput>().enabled = true;
Does not work. you have to disable first, then re-enable the PlayerInput
Component and mouse events will work!
[UPDATE]
So, disabling and re-enable did work, but I found out it caused an unintended side effect: other players could not join. All input devices would be registered to the existing player instead of a new input device spawning a new player. So, the real fix, after trial and error and detective work (literally hours debugging code) was to created a Control Scheme in the InputAction Asset. What was happening was the PlayerInputManager
was joining players when an InputAction
was triggered, in this case, the “Jump” Action and what the PlayerInputManager
was doing behind the scenes was tying the InputDevice that triggered the event to the new player. So, in this case, since the space bar was pressed, ONLY the keyboard was assigned to the player, NOT the mouse. When the Gamepad was pressed, then a new player was created and only the Gamepad was assigned to it. When I initially “solved it” by disabling then re-enabling the PlayerInput
, the side affect was that when it got re-enabled, it assigned it access to ALL input devices behind the scenes instead of tying it to only the keyboard. So, I could use the mouse, but no other player could join because the PlayerInputManager
thought the new device belonged to player 1. The REAL solution was to create a Control Scheme in the InputAction Asset
and mark the desired devices as required for that particular Control Scheme so that when the PlayerInputManager
detects input from a device, it actually assigns all the devices marked as required for that particular Control Scheme
1 Like
Blessed Be to You I spent 2 hours tryna figure this out