Search Unity

How to Edit an input action processor

Discussion in 'Input System' started by Proportion1, Mar 26, 2022.

  1. Proportion1

    Proportion1

    Joined:
    Jan 6, 2013
    Posts:
    35
    Hi i would like to change the sensitivity of my Look action. So i added a Scale Vector 2 processor to it.

    upload_2022-3-26_11-45-8.png

    I can see the inputAction.processors property to read it, but im not sure how you would go about editing the x and y value of the processor.

    Code (CSharp):
    1. public InputActionAsset inputActionAsset;
    2.     public InputAction Look;
    3.  
    4.     void Start()
    5.     {
    6.         inputActionAsset = GameObject.FindGameObjectWithTag("EventSystem").GetComponent<InputSystemUIInputModule>().actionsAsset;
    7.         Look = inputActionAsset.FindActionMap("Player").FindAction("Look");
    8.         Debug.Log(Look.processors);// returns ScaleVector2
    9.     }
    10.    
    11.     // this is attached to a UI slider
    12.     public void LookSensitivity(float sensitivity)
    13.     {
    14.         //this code doesn't work, just showing what i'd like it to do.
    15.         //Look.processors.ScaleVector2.x = sensitivity
    16.         //Look.processors.ScaleVector2.y = sensitivity
    17.     }
    I do understand i could just add a look multiplier to my player at runtime, i was just curious if there is a way to edit processors directly.
     

    Attached Files:

  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    ATM this requires setting an override on the binding.

    Code (CSharp):
    1. action.ApplyBindingOverride(new InputBinding {
    2.     overrideProcessors = "scaleVector2(x=1.2, y=1.3)"
    3. });
    In 1.4, there is a new API where this can be achieved directly.

    Code (CSharp):
    1. action.ApplyParameterOverride("scaleVector2:x", 1.2f);
    2.  
    3. // Or.
    4. action.ApplyParameterOverride((ScaleVector2Processor p) => p.x, 1.2f);
     
    Last edited: Mar 31, 2022
    Richay and (deleted member) like this.
  3. JeffreyBennett

    JeffreyBennett

    Joined:
    May 18, 2017
    Posts:
    25
    input_action_reference.png I'm missing a connection here, and I cannot seem to see it. If anyone sees the mistake I'm making please let me know.

    What is the thing that ties an input action reference to the input action itself? How is that connection built?

    I'm in Unity 2021.3.8f1 with Input System 1.4.2, player input module > UI_EventSystem, behavior: Send Messages

    For example, if I want to change the look inversion processor on a binding (It goes like this: Input Action Asset > Action Map > Action > Binding > Processor > Parameter (i.e setting) on the processor).

    Here is my code:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.EventSystems;
    3. using UnityEngine.InputSystem;
    4.  
    5. public class myScript : MonoBehaviour
    6. {
    7.  
    8.     public InputActionAsset inputActionAsset; //In the Editor Property panel, drag / drop the new input system's action map from the project assets to this slot
    9.     public InputAction inputActionLook;
    10.     public InputActionReference lookAction;
    11.  
    12. void Start()
    13. {
    14.  
    15. //Something somewhere, about here, should somehow say "lookAction refers to inputActionLook," but I don't know what does that. Do I drag something into the lookAction variable in the editor? Do I write code to do this? How is this link established?
    16.  
    17. lookAction.action.ApplyBindingOverride(new InputBinding {overrideProcessors = "invertVector2(invertX=false,invertY=false)" });
    18. }
    19.  
    20. }
    I've looked all over the documentation. I would think I'd find that information here > https://docs.unity3d.com/Packages/c...yEngine.InputSystem.InputActionReference.html

    Does anyone see what I'm missing about how to connect the input action reference to the input action itself?
     
    Last edited: Sep 5, 2022
  4. CausticLasagne

    CausticLasagne

    Joined:
    Oct 2, 2015
    Posts:
    26
    Hi. I know this was asked a while ago but I've tried the above code and also Rene-Damm's code. I can't seem to get it to work. I've managed to get the debug log to print out the values of the stick deadzone processor I have but I can't change them to new values. I've unticked default values in the input settings just in case.

    Code (CSharp):
    1. Debug.LogError("Processor Pre-Edit" + PlayerInputInst.actions["Look Camera"].processors);
    2. PlayerInputInst.actions["Look Camera"].ApplyParameterOverride("StickDeadzone:x", value.x);
    3. PlayerInputInst.actions["Look Camera"].ApplyParameterOverride("StickDeadzone:y", value.y);
    4. Debug.LogError("Processor Post-Edit" + PlayerInputInst.actions["Look Camera"].processors);
    I also tried the other type using StickDeadzoneProcessor but that didn't work either.
    Am I not doing something right?
     
    AndreIvankio likes this.
  5. Dawdlebird

    Dawdlebird

    Joined:
    Apr 22, 2013
    Posts:
    88
    To modify stick deadzone via script, it should look like this:
    Code (CSharp):
    1. action.ApplyParameterOverride("StickDeadzone:min", 0.3f);
    2. action.ApplyParameterOverride("StickDeadzone:max", 0.9f);
    x and y are for a scaleVector. And those 0.3f and 0.9f values should of course be variables.
    Alternatively, this can be written as:
    Code (CSharp):
    1. using UnityEngine.InputSystem.Processors; // <- without this you won't have the preprocessor classes available
    2.  
    3. action.ApplyParameterOverride((StickDeadzoneProcessor s) => s.min, 0.3f);
    4. action.ApplyParameterOverride((StickDeadzoneProcessor s) => s.max, 0.9f);
     
    Last edited: Jul 18, 2023
  6. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    156
    Are we really gonna pretend that using strings to get and apply 'static' stuff like processors was a good idea?
    Why is there no action.GetProcessor() or action.AddProcessor() and a Processor object we can interact with?
    This is some really poor thinking
     
    jjmcc2660 and VeryVeryKnopp like this.