Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Exposing input filters

Discussion in 'Input System' started by Tyndareus, Mar 19, 2020.

  1. Tyndareus

    Tyndareus

    Joined:
    Aug 31, 2018
    Posts:
    37
    Just wondering if its possible to achieve the same as the input action asset where you can either record or specify from a list of buttons/keys as a script entry.
    Without changing much of the current project keyboard needs to be processed so from a spawned prefab the input is directed through there which is then sent out to listening scripts. What id like to do is create callbacks that have specified input filters so if F3 is pressed do these callbacks if shift+delete etc...

    I had exposed an InputAction which could be set in the desired manner but they appear to be static references so adding another filter entry would just have the same data as the previous entry and changing either would affect the other.
    The underlying type (InputBinding) is simple string entries so assuming the version in the action asset is part of the editor scripting for the input system, this isn't just me that will be using it so I need it as simple as possible.
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Think I don't follow 100% what you're going for.

    As far as creating actions outside of assets, you can create them on the fly of have them as properties on components.

    Code (CSharp):
    1. // Put them as properties on components.
    2. // Can be configured in the inspector.
    3. public class MyComponent : MonoBehaviour
    4. {
    5.     // Single action.
    6.     public InputAction myAction;
    7.  
    8.     // Or an entire map.
    9.     public InputActionMap myMap;
    10. }
    11.  
    12. // Can also create actions entirely on the fly.
    13. var myAction = new InputAction(binding: "<Gamepad>/leftStick");
    14.  
    15. // Also maps.
    16. var myActionMap = new InputActionMap();
    17. myActionMap.AddAction("fire", binding: "<Gamepad>/buttonSouth");
     
  3. Tyndareus

    Tyndareus

    Joined:
    Aug 31, 2018
    Posts:
    37
    Similar to the InputAction field, you can add a binding to that specified action and be able to provide a path due to the InputControlPath/Dropdown editor stuff, so id be able to pass this on and whoever needs to set the scene up to listen for the space bar (simply because the input manager doesn't exist in this scene, its created in another scene) and they would just be able to click the drop down, click Keyboard->Space, add a callback and be done.

    While I am also here in the forum I am looking for button combinations but so far up to page 14 there hasn't been any mentions, so if I was to press alt+f4 how would I manage that? I currently have something where I just add the path of what has been pressed to an array and then join out the array as if it was a combo string but it looks like holding alt or shift or w/e takes priority on the callback event so my context is either always alt, or f4... With a coroutine I can make it so that it recognises alt+f4 but the actual action is alt press/release then f4 press/release