Search Unity

Resolved About On Input System Button On Released

Discussion in 'Visual Scripting' started by NizarSama, Jan 23, 2022.

  1. NizarSama

    NizarSama

    Joined:
    Apr 20, 2015
    Posts:
    10
    Let's just get to the point, there is this On Input System Event Button bug that if you set it on OnReleased the event is not triggered at all, instead it was triggered on the OnPressed too.

    so to solve this problem what you need is a custom node that check if the button was released.
    here's my code :
    Code (CSharp):
    1. [UnitCategory("CustomOnReleased")]
    2. public class CustomInputOnReleased : Unit
    3. {
    4.     [DoNotSerialize]
    5.     public ControlInput input;
    6.     [DoNotSerialize]
    7.     public ControlOutput output;
    8.     [DoNotSerialize]
    9.     public ValueInput inputGameObject;
    10.     [DoNotSerialize]
    11.     public ValueInput actionName;
    12.     [DoNotSerialize]
    13.     public ValueOutput releasedButton;
    14.     PlayerInput playerInput;
    15.     InputAction inputAction;
    16.     float released;
    17.     protected override void Definition()
    18.     {
    19.         input = ControlInput("input", flow =>
    20.         {
    21.             playerInput = flow.GetValue<GameObject>(inputGameObject).GetComponent<PlayerInput>();
    22.             inputAction = playerInput.currentActionMap.FindAction(flow.GetValue<string>(actionName));
    23.             released = inputAction.ReadValue<float>();
    24.             return output;
    25.         });
    26.         output = ControlOutput("output");
    27.         inputGameObject = ValueInput<GameObject>("Player Input");
    28.         actionName = ValueInput<string>("Action Name", "");
    29.         releasedButton = ValueOutput<float>("Button", (flow) => released);
    30.     }
    31. }
    32.  
    and here's how it look on the graph :
    on released.png

    for me it works like a charm, and if you want to trigger OnPressed only when it pressed you can use this too, just check the output to equal 1.

    hope that it'll helps, and i do hope that the fix come soon.
     
    Last edited: Jan 23, 2022