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. Dismiss Notice

Bug Not receiving input while focus lost

Discussion in 'Input System' started by TylerT_DreamToaster, Oct 17, 2021.

  1. TylerT_DreamToaster

    TylerT_DreamToaster

    Joined:
    Jul 19, 2021
    Posts:
    7
    I'm trying to receive input while the game is not focused. I can't get mouse or keyboard input working while the app is not focused. I'm making a utility for vtubers, so operating while other apps is focused is key.

    I've tested with 1.1.1, 1.1.0-pre.6, and 1.0.2. I've tried polling and callbacks.

    Code (CSharp):
    1. var mpos = ((Vector2)Mouse.current.position.ReadValue());
    Code (CSharp):
    1.  
    2. public InputActionReference MouseAction;
    3. ...
    4. MouseAction.action.performed += (x) =>
    5. {
    6.     MousePos = x.ReadValue<Vector2>();
    7.     Debug.Log(MousePos);
    8. };
    9.  
    When looking at the input debugger, new mouse states are generating but the mouse values are not updating (this may be an editor only behavior). The events are not called. On Start() the Mouse shows that it supports running in background.

    I've tried setting the Background Behavior setting to both "Reset And Disable Non Background Devices" and "Ignore Focus."

    The application is set to run in background. I've debugged to ensure that it is updating.

    I've attempted setting the Update mode to Dynamic Update and also manually calling Update.

    All of this is true for the Keyboard and Mouse.

    Editor is set to "All Device Input Always Goes To Your Game View."

    The problem persists in builds.

    I've put a lot of time into getting Input System working with my tool, but it's starting to feel like I might have to jump to Rewired. Any advice on what to attempt next or any potential fixes? It feels like this is a bug in the Input System package.

    EDIT: Clarified some verbiage.
     
    Last edited: Oct 19, 2021
  2. TylerT_DreamToaster

    TylerT_DreamToaster

    Joined:
    Jul 19, 2021
    Posts:
    7
    I tried out 1.0.2. Still running into the problem. I made an example project and build. Hopefully I got all the settings the same as my main project. Here is the project (build is too large to attach).

    Unity 2020.3.15f2
     

    Attached Files:

  3. TylerT_DreamToaster

    TylerT_DreamToaster

    Joined:
    Jul 19, 2021
    Posts:
    7
    I've started diving into the source code for the Input System and have not yet found any solutions. I will continue to try though. It would definitely seem that the problem lies in the Input System not in my use of it. I'm afraid it might be outside the scope of the open source portion of the Input System.
     
  4. TylerT_DreamToaster

    TylerT_DreamToaster

    Joined:
    Jul 19, 2021
    Posts:
    7
    I've finished my migration to Rewired. I'm keeping the Input System branch alive in my project to hopefully help figure out what's going on with this.
     
  5. pitchblende

    pitchblende

    Joined:
    Jan 9, 2020
    Posts:
    71
    Just as a sanity check, have you made sure the InputAction is enabled?
     
  6. TylerT_DreamToaster

    TylerT_DreamToaster

    Joined:
    Jul 19, 2021
    Posts:
    7
    Yup :c
     
  7. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    Keyboard in background is unlikely to work, because then we will be a keylogger, which some OS don't allow.

    If you do this with Debug.Log in Update() of some MonoBehaviour, does it print correct values when the editor is not in focus?
    Code (CSharp):
    1. var mpos = ((Vector2)Mouse.current.position.ReadValue());
    If yes, problem is somewhere in InputAction layer, might be misconfiguration or edge case we missed
     
  8. SharpAccent

    SharpAccent

    Joined:
    Jul 19, 2018
    Posts:
    38
    Any update on this?
     
  9. TylerT_DreamToaster

    TylerT_DreamToaster

    Joined:
    Jul 19, 2021
    Posts:
    7
    I had to migrate my project to Rewired. Which was able to get me the input I needed while unfocused. I haven't checked in on it since.