Bug? Disabling PlayerInput onDeath causes problems with UI not registering clicks

Hello,

I'm using the new unity input system and I noticed problems when the player dies and PlayerInput is disabled - the default behavior.

After the player dies I show UI, where you have to click a button to respawn, the problem is that even though the button is registering highlight events, click events (visually), none of the on click actions are triggered unless I click the button 2 or 3 times.

The problem appears after the first respawn (you need to die twice to trigger the bug, then after than on each death you won't be able to fire button events unless you click it 2 or 3 times). It happens with any kind of UI.

The only way to fix the issue is to open PlayerInput.cs and go to line 500 and comment out the "enabled = m_AllowInput && !m_Death;"

private void OnDeath(Vector3 position, Vector3 force, GameObject attacker)
{
m_Death = true;
// enabled = m_AllowInput && !m_Death;
}

I also couldn't find a reason why PlayerInput gets disabled when using the new unity input system, even if I remove that line and the script stays active while the player is dead I still can't move the player around, so I don't see a point in disabling this script, or maybe there's another rare case scenario and you have to disable it?

-----

A way to replicate it:

1. Use latest UCC + latest Unity Input System
2. Create a simple script that shows a button when you press a key or when you die, add an onclick event to the button to make it's text disappear or something simple like that
3. Get killed by NPC or jump off a cliff
4. Show the UI with the button

on the first trial the click will register properly

5. Respawn
6. Die again
7. Show the UI again with the button, now it will take 2 or 3 clicks to trigger the on click event

from here every time you die, none of your button UIs will register clicks unless you click on them multiple times.
 
Can you explain what you mean by show the UI with the button?
If you mean explain step 4, it's just showing the UI from step 2, create a canvas with a button that has on click event to set it's text to disabled (also make a script to re-enable the text component when the button gets enabled). Right after you die, show the UI (maybe make a simple script to listen for OnDeath event and show the UI or even easier, upon pressing "U" key, activate that UI) and try to click the button, first the text will get disabled right away as it should, but upon dying a second time, showing the UI and clicking the button it will take you 2 or 3 clicks to fire the on click events.

I also don't let UCC control my cursor, I do it manually when I show that specific UI, by just setting the cursor mode to None and visible to true.
 
Can you attach a package with just the repro scene and script so it's easier to reproduce?
 
Can you attach a package with just the repro scene and script so it's easier to reproduce?

I've tried to make a new project and get UCC to work with the new input system, but it's a very hard thing to do, lots of errors from the get-go, character not responding to inputs, demo scenes throwing runtime errors and not working and when I created my own the character wasn't responding to inputs again. To be honest, I think I was very lucky to get it to work on my main project.

I have wasted a few hours and can't spend more time on this, the scripts you need to make are literally 3 with 5 lines each, or at least if I can get a working demo scene I can try them. Or if you confirm UnityInputSystem could stay active on death maybe I can keep it active and comment out the enabled line from above as a workaround.
 
Last edited:
Happy New Year!

Upon further testing I found out why the problem appears, I have all of my EventSystem actions in the same input actions asset I use on the PlayerInput component, so when UnityInputSystem gets disabled, the click events from the UI aren't firing. One other solution is to create a new InputActions asset and copy paste the action map to it and use that separate asset for the EventSystem. Still though I haven't found any problems if I keep the UnityInputSystem component active the entire time the player is dead.
 
Hey there,

we are using the Unity Input System... and the following occurs:

  • We play a 2-player local game with Gamepad #1 and Keyboard #2
  • Player with keyboard (#2) gets killed (OnDeath)
  • Now the InputComponent (#2) is deactivated
  • After the death of the Gamepad player (#1),
  • s/he player (#1) is assigned a new controller, which will be the keyboard

We will try that workarround on top of the thread (commenting out that line)
Any ideas how to "really" fix this?
 
What is assigning the keyboard? I think the proper fix for this is to figure out what is doing the input reassignment and prevent that from happening.
 
Top