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

About OnScreenControl One-Frame Lag. Any updates?

Discussion in 'Input System' started by mm_hohu, Oct 12, 2021.

  1. mm_hohu

    mm_hohu

    Joined:
    Jun 4, 2021
    Posts:
    38
    According to the Unity source code, there is a delay of one frame when using the OnScreenControl, is this still be the case in 2021?

    If there is a better solution to this problem, please let me know.

    // OnScreenControl.cs Line 194
    Code (CSharp):
    1.  
    2. ////FIXME: this gives us a one-frame lag (use InputState.Change instead?)
    3. m_InputEventPtr.internalTime = InputRuntime.s_Instance.currentTime;
    4. control.WriteValueIntoEvent(value, m_InputEventPtr);
    5. InputSystem.QueueEvent(m_InputEventPtr);
    6.  
     
    Lejv likes this.
  2. Lejv

    Lejv

    Joined:
    Nov 19, 2014
    Posts:
    7
    We are having issues with this, please respond
     
  3. andrew_oc

    andrew_oc

    Unity Technologies

    Joined:
    Apr 16, 2021
    Posts:
    77
    Hi there, by default there is still a one frame delay when using OnScreenControl. One thing you could do if you absolutely need to process the input in the same frame is to take control of the input system update by setting the Update Mode to Process Events Manually (Project Settings -> Input System Package), and then have a MonoBehaviour that calls InputSystem.Update once in it's Update method and again in LateUpdate, or at any other two points that make sense for your use case. The downside is you'll be paying a performance cost for pumping the input system twice per frame, but that might be an ok trade-off for you.
     
    mm_hohu likes this.
  4. Lejv

    Lejv

    Joined:
    Nov 19, 2014
    Posts:
    7
    I can try but I think this is cause of a bug, where OnScreenButton does not register OnPointerUp when it is exactly 1 frame after OnPointerDown (same frame is ok, other frames after also ok).

    You can create empty project, setup new InputSystem, create a button in InputActions with keyboard binding, Put OnScreenButton on canvas, setup targetFrameRate to 1 (for easy debuging), and log InputActionPhase of the action.
    Works ok in editor but not in build.
    Also works if instead of a button you create a Value-Vector2 with stick binding
    Does not work for Value-Analog with keyboard binding
     
    Last edited: Nov 16, 2021
  5. andrew_oc

    andrew_oc

    Unity Technologies

    Joined:
    Apr 16, 2021
    Posts:
    77
    Hi @Lejv , sounds like a different issue than the OP. We'd definitely appreciate if you could create a bug report for this one (Unity Editor -> Help -> Report a bug).