Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Bug InputSystemUIInputModule doesn't invoke 'IPointerUpHandler' etc. on device removed

Discussion in 'Input System' started by Gooren, Feb 6, 2022.

  1. Gooren

    Gooren

    Joined:
    Nov 20, 2015
    Posts:
    315
    Hi,

    We are using a customized VirtualMouseInput class. Everything works nicely until player holds a UI button pressed down and the virtual mouse gets removed (in VirtualMouseInput OnDisable) during that time frame.

    At that point, the Button stays in the "pressed down" state, even though the virtual mouse is long disabled and the cursor is hidden.

    I had to do two things to get a workaround solution working:
    Code (CSharp):
    1. // Add this at the top of the OnDisable method of the VirtualMouseInput class
    2. InputState.Change(m_VirtualMouse, new MouseState());
    3.  
    4. // ---
    5.  
    6. // OR AN ALTERNATIVE SOLUTION (you may pick only one at a time)
    7. // First you must make sure that in OnDisable you first disable the actions and only then remove the VirtualMouse device.
    8. // Secondly, change the following line in OnButtonActionTriggered
    9. var isPressed = !context.canceled && context.control.IsPressed();
    10. // This alternative solution corrects the state "automatically" for you.
    Code (CSharp):
    1.         // Modify the following method in the InputSystemUIInputModule class
    2.         private void SendPointerExitEventsAndRemovePointer(int index)
    3.         {
    4.             var eventData = m_PointerStates[index].eventData;
    5.             if (eventData.pointerEnter != null)
    6.                 ProcessPointerMovement(eventData, null);
    7.  
    8.             // <MODIFIED CODE>
    9.             var leftButton = m_PointerStates[index].leftButton;
    10.             if (eventData.pointerPress != null || eventData.pointerDrag != null)
    11.             {
    12.                 ProcessPointerButton(ref leftButton, eventData);
    13.                 ProcessPointerButtonDrag(ref leftButton, eventData);
    14.             }
    15.             // </MODIFIED CODE>
    16.  
    17.             RemovePointerAtIndex(index);
    18.         }
    So there were two problems.
    - First problem is that the VirtualMouse state does not restart when disabled. Fixed in the first code block.
    - Second problem is that InputSystemUIInputModule does not call UI callbacks like 'IPointerUpHandler' when a device is removed. It only does so when updating active devices in the update loop. But not on remove. Fixed in the second code block.

    Regards,
    Stepan
     
    Last edited: Feb 6, 2022
  2. Gooren

    Gooren

    Joined:
    Nov 20, 2015
    Posts:
    315
    I forgot to mention versions used:
    - Unity 2020.3.27f1
    - Input System 1.3.0 (but I also checked latest version on github, pending pull requests included)

    I'm afraid I will have to call upon the powers of the Input System father himself, @Rene-Damm :D
     
  3. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Heya, if possible, could you file a ticket for this with the Unity bug reporter? Ensures this is properly tracked and verified by people other than me (important to make sure stuff *actually* happens :)).
     
    Gooren likes this.
  4. Gooren

    Gooren

    Joined:
    Nov 20, 2015
    Posts:
    315
    Oh god... I can't. I'm traumatized after squeezing some bug reports through Unity QA in the past. It always takes insane amount of effort to convince people there that I'm not just another guy who doesn't know how to turn on his monitor.

    I just found a bug and wanted to share it. I prefer talking about it to someone who knows the actual thing in question.

    Don't get me wrong. I don't intend to be rude or anything. I'm just overloaded with work and life stuff in general and can't spend any more time on this. I found a solution that works and that's it for me. Creating a foolproof repro project for someone who probably never even used Input System before is just beyond my abilities ATM.

    I hope this thread at least helps someone who bumps into this in the future.
     
  5. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Doesn't need to be a perfect repro project. In my experience, our QA guys are pretty good at stripping down a repro project to the essential parts. Also, linking this thread will go a long way in ensure the QA person will end up pinging me when the ticket surfaces on the queue.