Search Unity

Question Proper way to handle processors

Discussion in 'Input System' started by Memoriesin8bit, Aug 8, 2020.

  1. Memoriesin8bit

    Memoriesin8bit

    Joined:
    Feb 20, 2020
    Posts:
    10
    Hello forum,

    first thread here, so I apologize in advance for missing some of the "obvious things to check first", but I hope you can still help me. :)

    I have recently migrated my project to the new Input System, mainly to have a way to properly remap controls, which is working really nicely.

    However now I would also like to provide options for sensitivity, axis inversion, etc. and since I would like to have them separate for each input device (i.e. gamepad and mouse), it made most sense to do this via a processor for the designated bindings.

    Now the documentation still seems to be pretty sparse when it comes to working with processors, but I was able to figure out that I can set them using something like this:

    Code (CSharp):
    1. myAction.ApplyBindingOverride(bindingIdx, new InputBinding { overrideProcessors = "Scale(factor=2.14),Invert"});
    Now the question is: How would I got about to read out the currently stored processors so my sensitivity slider and Invert toggles can switch to the states the current processors are currently set to?

    Code (CSharp):
    1. action.bindings[bindingIdx].effectiveProcessors
    is giving me a string that I could parse for the scale factor and checking if "invert" is part of the string, but there sure has to be a better way to get to these states, right? Unfortunately I wasn't able to find this information so I hope you might be able to help me.

    Thank you in advance! :)
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    ATM, in most cases, the best option for when processors need to be configured dynamically is to have dedicated/custom processors that read out configuration from elsewhere. Essentially the same thing the built-in processors/interactions do for InputSettings.defaultButtonPressPoint.

    While it is possible to dynamically reconfigure processors through binding overrides, it is a rather awkward and fiddly way.

    Proper APIs for doing this stuff are in the works. The WIP version looks something like

    Code (CSharp):
    1. // Read.
    2. playerInput.actions.GetParameter<float>("tapDelay");
    3.  
    4. // Write.
    5. payerInput.actions.SetParameter("tapDelay", 0.25f);
    Which can be done at the level of assets, action maps, or individual actions. ATM it's string-based but we're looking at having an alternate API not having strings.

    But yeah, not yet released so probably not that helpful.

    The syntax here is shared and reused in several places and there's a public API in the Utilities namespace that can be used if one wants to manually parse out the data.

    Code (CSharp):
    1. var binding = playerInput.actions["look"].bindings[0];
    2. var processors = NameAndParameters.ParseMultiple(binding.processors);
    3.  
    4. foreach (var element in processors)
    5. {
    6.     Debug.Log($"Processor: {element.name}");
    7.     // 'parameters' contains an array of NamedValue elements.
    8.     Debug.Log("Parameters: " + string.Join(",", element.parameters);
    9. }
    But yeah, it's indeed quite cumbersome this way. GetParameter/SetParameter is intended to solve this.
     
  3. Memoriesin8bit

    Memoriesin8bit

    Joined:
    Feb 20, 2020
    Posts:
    10
    Thanks so much for your reply, Rene! :)

    I was actually wondering if this approach was supposed to be the intended way, while the existing processors you cam set up were meant merely to offset base differences between input devices - establishing the baseline so to say.

    This is actually quite cool. And sorta funny, because I was stumbling through the documentation (I often learn best on examples) and even ended up trying to "Get" processor variables in a similar way. To no avail of course.

    But this looks very promising, I cannot wait! :)


    To be honest, this might just do the trick for now. And the way I set this up it may be easy to adjust once the proper API is in place - which might easily happen before I actually release the game ... there's still a lot to do.
     
  4. ProceduralCatMaker

    ProceduralCatMaker

    Joined:
    Mar 9, 2020
    Posts:
    108
    I wonder if someone can help me on this simple issue that is driving me nuts.
    For an action (say jump) I would like to check the status of a keyboard key (say space) setting a boolean true in the start phase and false in the canceled phase, returning this boolean value in the callback from the Player Input for the action (Jump).
    Of course I can do my own monoBehaviour checking the context and doing what i want (already done) but i think a cleaner way would be to add a processor and do checks there, kind like in the native Invert .
    My problem is that processors seem not to like bools and I have found no way to solve the issue.
    Any suggestions, help.
    Anyway, is it the correct and cleanest way to handle this issue?

    Post Scriptum
    For anyone who might be interested: I was able to handle this in 2 ways

    create a public class BoolProcess : InputProcessor<bool>
    and in it include a public override bool Process(bool boolValue, InputControl control)

    the issue is that when you are in the Actions Editor window the only way to bind this boolean processor that I have found is to set ActionType to Pass Through and Control Type to Any.
    Then everything works, returning a true for the start of the action and a false at the end canceled phase.

    in your controller you will have to handle the callback response using a special ReadValue:
    public void OnTestBool(InputAction.CallbackContext context)
    {
    testBoolValue = context.ReadValueAsButton();
    }

    A similar result can anyway be achieved with a more traditional float processor that allows you to use (probably in a cleaner way) the Action Editor where you can set ActionType to Button and manage returned 0 or 1 float values as booleans.

    If someone has something to comment on this matter is very welcomed.
    bye
     
    Last edited: Oct 13, 2020