Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Updating Input System manually doesn't seem to be working

Discussion in 'Input System' started by CR0N14, Mar 27, 2024.

  1. CR0N14

    CR0N14

    Joined:
    Sep 23, 2021
    Posts:
    6
    My game has its own update loop for deterministic networked logic, thus the need for the InputSystem to be updated manually each frame of my custom update function. I should have set everything up properly:

    1. Set 'Process Events Manually'
    upload_2024-3-27_10-14-44.png

    2. Call 'InputSystem.Update' in my custom update function
    upload_2024-3-27_10-22-16.png

    However, I find that input events aren't being fired. I suspect that the problem could lie with Unity's Input System itself, because running my code but with the setting 'Process Events in Dynamic Update' enabled instead allows the input events to fire and everything to work properly, leading me to believe that 'Process Events Manually' and the 'InputSystem.Update()' method might not be working as intended.

    According to this old forum post, a Unity developer himself confirms that what I have tried should be how it works*, with the only difference being that 'InputSystem.Update(InputUpdateType.Manual)' is called instead of simply 'InputSystem.Update()'. However, this isn't possible anymore. Looking at the source code, the parameter version of InputSystem.Update is now internal, not public, so I can't call it:

    upload_2024-3-27_10-32-55.png
    upload_2024-3-27_10-34-16.png

    *technically, he comments that it is broken at that time. However, looking at the ticket he filed, it is announced later that the bug is fixed and it should be working now.
     

    Attached Files:

  2. siimonhansson

    siimonhansson

    Joined:
    May 23, 2019
    Posts:
    6
    'Process Events Manually' and the 'InputSystem.Update()' method works as intended in my testing. My immediate thought is that it's an issue with script execution order. You want to make sure that the script that updates the input system is run before 'Default Time' and 'UnityEngine.InputSystem.PlayerInput'. Also, make sure that the input system is only updated once per frame.

    Keep in mind that the documentation advises against updating the input system manually as it might lead to unintended behaviour. An example of this that I've run into is that Unity's event system navigation will break entirely, so unless you're using your own system for UI navigation you will run into issues there.
     
  3. CR0N14

    CR0N14

    Joined:
    Sep 23, 2021
    Posts:
    6
    Thanks for replying! I tried what you suggested but it sadly still doesn't work for me.
     
  4. siimonhansson

    siimonhansson

    Joined:
    May 23, 2019
    Posts:
    6
    How are you reading input? If you're using the polling API, that also breaks when updating the input system manually.
     
  5. CR0N14

    CR0N14

    Joined:
    Sep 23, 2021
    Posts:
    6
    I'm using the auto generated C# class, and calling methods like IsPressed(), IsInProgress(), WasPerformedThisFrame(), etc. That's the polling API right.

    So based on what you've said, if I want manual updating to work, I should instead use the PlayerInput component with its behaviour set to Invoke C#/Unity events, and ensure the script execution order is correct.
     
  6. siimonhansson

    siimonhansson

    Joined:
    May 23, 2019
    Posts:
    6
    That right! Although you don't necessarily have to use the PlayerInput component. You can just subscribe to the events you want to listen to in same script where you called "IsPressed()" etc. before.
     
  7. citizen-erased

    citizen-erased

    Joined:
    May 2, 2022
    Posts:
    5
    I'm not sure what's happening in your case but I also update InputSystem manually and it appears to be working normally. I call
    InputSystem.settings.updateMode = InputSettings.UpdateMode.ProcessEventsManually;
    when the game starts but this should do the same thing as setting Update Mode in the editor GUI.

    The other difference is that I'm calling
    InputSystem.Update()
    during the ScriptRunBehaviourUpdate phase of the PlayerLoop, i.e., when
    Update()
    is called on scripts and when InputSystem's dynamic update option would trigger updates. My use case here was to set up per-frame state, process the event stream from InputSystem, then continue with per-frame processing.

    I'm also using the auto generated C# class. So far I haven't run into any issues with callbacks or polling not working.