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 or Intentional?

Discussion in 'Input System' started by EvgenyVasilyev, Dec 16, 2020.

  1. EvgenyVasilyev

    EvgenyVasilyev

    Joined:
    Jul 5, 2019
    Posts:
    7
    Hello, I've encountered a problem today that has been driving me crazy.
    My situation is this, when an InputAction is Triggered (Started / Canceled) -> Item is equipped -> Item Registered to listen for the same InputAction. The issue is the InputAction is triggered immediately instead of on the next time it is (Started / Canceled).
    (Yes, my input actions are setup as Buttons)

    After debugging I noticed that inside the DelegateHelpers.cs class in the InvokeCallbackSafe method the callbacks are looped from start to end. This causes a problem if the invoked callback appends more callbacks since the list grows and those new callbacks get called immediately.

    Was this intentional behavior?

    *Edit*
    The solution isn't quite as simple as iterating over the loop backwards. Since there are potential issues if callbacks are added and removed at the same time. Only thing I can think of is Cloning the list before iterating.

    *Original*
    The solution seems simple, just iterate over the list from end to start, so as to avoid invoking any callbacks that are appended to the list that frame.

    upload_2020-12-16_14-43-29.png
     
    Last edited: Dec 18, 2020
  2. EvgenyVasilyev

    EvgenyVasilyev

    Joined:
    Jul 5, 2019
    Posts:
    7
    Hmm, iterating from the end won't exactly solve the issue if a callback is added and removed at the same time.

    I think the only solution is to Clone the InlineArray?

    I've submitted a pull request as I don't think this is not an intended behaviour
     
    Last edited: Dec 18, 2020