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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Is there a way to prevent player bind same keys when rebinding at runtime?

Discussion in 'Input System' started by Nkp46, Apr 9, 2022.

  1. Nkp46

    Nkp46

    Joined:
    Nov 10, 2016
    Posts:
    8
    I have a question about the Input System.

    If bind the same keys to the Vector2 composite, can`t get the correct result.
    This is the same whether bind it like an image or rebind it from C# at runtime.

    I have a key config implemented in my game under development.
    Is there a way to prevent player bind same keys when rebinding at runtime?

    This is the source code for the rebind.
    Code (CSharp):
    1.  action.PerformInteractiveRebinding()
    2.                 .WithTargetBinding(action.GetBindingIndexForControl(control))
    3.                 .OnComplete(operation => RebindComplete(operation))
    4.                 .OnCancel(operation => RebindCancel())
    5.                 .OnMatchWaitForAnother(0.1f)
    6.                 .WithControlsHavingToMatchPath("<Gamepad>")
    7.                 .Start();

    The version of the Input System is 1.3.0.
    The version of Unity is 2020.3.30f1

    upload_2022-4-10_3-21-32.png
     
  2. Nkp46

    Nkp46

    Joined:
    Nov 10, 2016
    Posts:
    8
    After the rebinding was finished, I compared the effectivePath of the bindings of all InputAction,
    and if there were multiple same ones, I called ApplyBindingOverride method and overwrote it with a different key,
    and it was solved by eliminating the duplication.