Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Cannot send multiple DPAD events quickly

Discussion in 'Input System' started by ltomov, Sep 17, 2023.

  1. ltomov

    ltomov

    Joined:
    Aug 3, 2017
    Posts:
    96
    I'm trying to implement InputSystem support for a device and I need to be able to quickly send multiple DPAD events (or whatever else works for UI navigation). For example 5 times move-left in ~100ms (I guess 500ms may also work, but the quicker - the better).

    The way I do it now is like this (pseudo-code):
    Code (CSharp):
    1. InputSystem.QueueStateEvent(DPAD, LEFT_BUTTON_DOWN, 0);
    2. InputSystem.QueueStateEvent(DPAD, LEFT_BUTTON_UP, 0.3f);
    3. InputSystem.QueueStateEvent(DPAD, LEFT_BUTTON_DOWN, 0.6f);
    4. InputSystem.QueueStateEvent(DPAD, LEFT_BUTTON_UP, 0.9f);
    5. ...
    The last parameter is time in seconds - it works like a delay - so these events are executed with 0.3s apart from each other. Input system update mode is "FixedUpdate" otherwise that time parameter is ignored.

    And here is the problem - 0.3s is too much for my needs, but if I lower that interval, some events get skipped. So instead of moving left 5 times, it moves left 3-4 times.

    Is there any way I can work around this?
    Also is there any better device to use for the task, instead of DPAD. Apparently with DPAD I need to send down-up-down-up events, can't do down-down.

    Any help is much appreciated. Thanks!
     
  2. ltomov

    ltomov

    Joined:
    Aug 3, 2017
    Posts:
    96
    It turned out my buggy code was sending a lot of mistimed "button-released" events which were causing a mess. By fixing that and also increasing the FPS to 50 I was able to increase the interval to 0.02s which seems to be pretty smooth.

    Now the only inconvenience remains the fact that the input system update mode must be set to "fixed update" in order for the time parameter above to work.
     
    Last edited: Sep 18, 2023