Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Discussion UI input module ignores input interactions and processors

Discussion in 'Input System' started by sodarocketstudios, Jan 24, 2024.

  1. sodarocketstudios

    sodarocketstudios

    Joined:
    Jan 14, 2021
    Posts:
    21
    The problem:

    I was remapping the UI controls in the UI input module for use with some custom UI elements. Some of these elements use the ISubmitHandler and ICancelHandler interfaces to determine when the user is holding the submit button. I was under the impression that I would be able to map my submit and cancel actions and use the Press interaction to trigger the callbacks on press and on release respectively. That wasn't the case. Instead, both cancel and submit would be called only when I press the button.

    The culprit:

    After digging around in code for awhile, I discovered the culprit was the UI input module that was handling these callbacks. Instead of invoking the events when the input action is performed, it only checks if the mapped button had been pressed that frame successfully ignoring everything provided else by input actions.

    The solution:

    By changing one simple call, I was able to fix the problem
    instead of

    Code (CSharp):
    1. if (cancelAction != null && cancelAction.WasPressedThisFrame())
    2.     ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.cancelHandler);
    and

    Code (CSharp):
    1. if (!data.used && submitAction != null && submitAction.WasPressedThisFrame())
    2.     ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.submitHandler);
    I changed the second condition to

    Code (CSharp):
    1. if (cancelAction != null && cancelAction.WasPerformedThisFrame())
    2.     ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.cancelHandler);
    3. if (!data.used && submitAction != null && submitAction.WasPerformedThisFrame())
    4.     ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.submitHandler);
    Simply changing WasPressedThisFrame to WasPreformedThisFrame means the UI input isn't ignoring the actions that I purposefully setup. I'm just left wondering why it was setup the way it was.
     
    Last edited: Jan 24, 2024