Search Unity

My Extension to the New Input System (binding composites with unlimited negatable modifiers)

Discussion in 'Input System' started by TRS6123, Sep 1, 2021.

  1. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    I created a repo on Github extends the functionality of Unity's New Input System! Includes binding composites with unlimited modifiers, negatable modifiers, and normalizing mouse input based the size of the screen.

    Using composite bindings:
    1. Open up an existing or create a new Input Actions Asset
    2. Select an existing or create a new Action Map
    3. Select an existing or create a new Action, and select an appropriate action type and control type (i.e. "Pass Through" and "Axis")
    4. To add a Single Axis Composite with Modifiers, click the plus sign on the action and select "Add Axis with Modifiers Composite"
    5. To add a Multiple Axis Composite with Modifiers, click the plus sign on the action and select "Add Vector2/Vector3 with Modifiers Composite"
    6. Select a binding for the axis/axes and another for the modifier (i.e. RightArrow + Shift)
    7. To add an inverted axis, right click the existing axis binding and select "Duplicate" in the pop-up, select a new binding, and add an "Invert" processor to the binding
    8. If multiple axis bindings are used for a specific axis, the binding prodicing the value with the highest magnitude is selected.
    9. To add additional modifiers, right click the existing modifier bing and select "Duplicate" in the pop-up and select the new binding.
    10. To negate a modifier, select the modifier and add a "Negate Button" processor to the binding (do NOT use the Invert processor because it won't work for modifiers)
    11. If multiple modifiers are used, all non-negated modifiers must be pressed and all negated modifiers must not be pressed in order to produce a non-zero value in the axis/axes.
     
    ChichoRD and NotaNaN like this.
  2. ChichoRD

    ChichoRD

    Joined:
    Jul 31, 2020
    Posts:
    19
    Would be possible with your extension of the system to use a 2d vector composite (The thing you do to map 4 inputs to 2 axis, for instance WASD, UP/DOWN/LEFT/RIGHT) with a modifier like shift or ctrl keys?

    Right now the native Input System only lets me do this with a single binding that is itself a 2d vector like mouse position but I need it for other things such as WASD movement.
     
  3. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    Yes. That is what I was trying to imply with point 7. It should look like this if you set it up properly (make sure you add Invert Processors to the A and S bindings): InputTest.png
     
  4. ChichoRD

    ChichoRD

    Joined:
    Jul 31, 2020
    Posts:
    19
    Thank you! Cloning that repository right now for my project!
    I'll tell you if any errors occur
     
  5. ChichoRD

    ChichoRD

    Joined:
    Jul 31, 2020
    Posts:
    19
    Unfortunately my other inputs freeze for some reason and don't get fired with their events.
    Also, how does your extension handle the started, performed and cancelled events?
     
  6. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    What version of the Unity Editor and Input System are you using? I know that the latest version of the Input System (1.4.1) introduces breaking changes to my extension. Can you provide a project for me to investigate?

    My extension is independent of the start, performed, and cancelled event APIs. It's core functionality comes primarily through the use of custom floating-point comparers used in my own custom binding composites.
     
  7. ChichoRD

    ChichoRD

    Joined:
    Jul 31, 2020
    Posts:
    19
    Oh, yes, 1.3.0 had some bugged features that were to be fixed in the following 1.4.0 so I updated some days ago but also broke other stuff of the input system.

    Additionally I updated to 1.4.2, is there a nice spot in the exact version 1.4.0 where your extension works, and the input system is completely functional with its own things?

    Regarding inputs events, how can I detect my input via your system if you say not to use input events (started, performed, cancelled). Do I have to cache them in an update loop? I thought that the event system was the main strength of this new system unity provided.
     
  8. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    I read the changelog for 1.4.0 which mentions that it added mutually exclusive handling of modifiers (which is the main problem my package extension is designed to tackle). It mentions that you can disable the feature by calling the following API:
    InputSystem.settings.SetInternalFeatureFlag("DISABLE_SHORTCUT_SUPPORT", true);
    Calling this code in one of my projects using 1.4.1 allows me to use my extension without a hitch. You'll want to use either Unity's implementation or my extension, but you can't use both.

    I think you misread what I'm saying about event handling. You should be able to use the started, performed, and cancelled APIs normally with my extension. They should not fight each other.