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

How to override Action Binding processors from code?

Discussion in 'Input System' started by EmeraldPawn, Feb 25, 2020.

  1. EmeraldPawn

    EmeraldPawn

    Joined:
    Jan 16, 2016
    Posts:
    5
    Hi all!

    My problem is simple, i want to be able to override processors on action bindings just like you can rebind the whole binding path. I've looked through all documentation i could get my hands on, and even tried overriding the binding processor through its string value, but no luck so far.

    Does anybody know if there is a proper way to override processors in the current version of the Input System?

    Cheers!
     
  2. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Setting overridePath in InputBinding should do the trick.

    Code (CSharp):
    1. myAction.ApplyBindingOverride(1, new InputBinding { overrideProcessors = "scale(factor=2)");
     
  3. EmeraldPawn

    EmeraldPawn

    Joined:
    Jan 16, 2016
    Posts:
    5
    Thank you very much! I'll try that the next time i have time to mess with that part of our implementation of user rebindable controls.
     
  4. Michael2790

    Michael2790

    Joined:
    Nov 27, 2017
    Posts:
    10
    How do I swap keys during binding. If new key binding already exist in the action map
     
  5. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,145
    Like you iterate the action map and check what action is using the new key binding.
    Then you can just reset the existing binding and apply the value to the action you want to re-bind or create a new action variable to hold the value of the action you want to re-bind, and then swap values of both actions by copying the value of existing one to the current and then the value of the temp variable to the existing one !

    Does this make sense ?

    TIP : i would recommend not setting up action maps default values from inspector if you would implement a re-bind functionality but simply create some script which initializes the action map from Awake directly working with "overridePath" variables because if you detect an existing value that you want to swap which is added to the main "path" value you wouldn't be able to remove the value as it's read only... working with "overridePath" gives you the option to leave an action value empty ( as inactive ) which you otherwise can not achieve if you have a default value added to the "path" value !
     
  6. downstroypvp

    downstroypvp

    Joined:
    May 30, 2016
    Posts:
    35
    Unless I misunderstood your tip, that is not exact. You can override the action binding you want to remove the binding for with an empty string in the overridePath to achieve the effect you describe (having an action with no bindings), see reference: https://docs.unity3d.com/Packages/c...yEngine_InputSystem_InputBinding_overridePath

    Specifically under overridePath:
    "This property can be set to an empty string to disable the binding. During resolution, bindings with an empty effectivePath will get skipped."