Search Unity

Layered Action Maps?

Discussion in 'New Input System' started by PeteMichaud, Dec 5, 2019.

  1. PeteMichaud

    PeteMichaud

    Joined:
    Jul 11, 2015
    Posts:
    25
    I've been trying to implement the new system into my game for the past couple days and one thing I can't figure out is how to use multiple action maps at once, or if it's even possible.

    I'm used to input systems that have a stack of action map equivalent objects, that each take precedence over the last. So for example I might have a base map that says something like Esc opens the main menu, and layer a player movement map on that which doesn't define the Esc, so Esc gets passed through to the base map. Then I layer on a UI action map that defines Esc as closing the UI (and blocking from further propagation).

    Is it possible to do this with the new input system?
     
    Ferazel and seffles like this.
  2. PeteMichaud

    PeteMichaud

    Joined:
    Jul 11, 2015
    Posts:
    25
    I'd really like an answer to this question. Is this not the right forum to ask it?
     
  3. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    355
    I would like this feature too. There are many times where I want to open an in-game menu with a start/esc button and I want that to happen when the player is on foot, in a vehicle, in a conversation etc. I'm guessing you can handle this action in code or duplicating the action for each of the action maps. The duplication though causes problems for rebinding if I want the game to be able to treat the bind as the same bind for every action map. I'm guessing again you could probably write some code to update the binding for all of the action maps. A built-in system for sharing action maps between contexts at the asset level would be spiffy though.
     
  4. seffles

    seffles

    Joined:
    Oct 2, 2013
    Posts:
    27
    I don't think this feature exists in the current API, but I'm hoping we can add it to the list of feature requests for a post 1.0 release.
     
  5. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    862
    This is super high on the priority list and one of the next things on my own list.

    I've recently dug a bit into that and my current thinking is to make two changes to the system:
    1. When a control triggers its change monitor, instead of directly firing the associated action, the system instead goes and looks for the "most suitable" action to fire from the given event. This will take precedence according to the ordering of action maps as well as of individual actions in maps into account but also things such as a binding of "CTRL+B" needing to override a binding to just "B" in case both CTRL and B are currently pressed.
    2. The system then triggers the action and afterwards checks whether it consumed the input. If not, it takes the "next most suitable" action and does the same and so on. Each event will get processed only once regardless of how many control change monitors it sets off.
    With this in place and without any user code changes, the system would automatically take layering of action maps in assets into account and would also correctly handle things such as composite bindings such as CTRL+SHIFT+B pre-empting input on other bindings. At the same time, it would allow action callbacks to dynamically decide whether to let events pass through or not -- e.g. the UI input module can decide based on whether a UI element consumed the input, if the action should consume its input or not.

    I haven't actually gone and tried implementing this so could be that it won't quite hold up in this form but FWIW, thought I'd just give a brain dump about where this is at ATM.
     
  6. matthew-holtzem

    matthew-holtzem

    Joined:
    Sep 1, 2016
    Posts:
    22

    With this change would that mean that basically all action maps would always be enabled and individual actions on lower priority action maps will only be ignored if there inputs are consumed by higher priority actions?
     
  7. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    862
    The set of enabled maps would still be under your control but yup, if multiple maps are enabled, then higher priority actions will prevent input from reaching lower priority actions except if explicitly letting it through.
     
    matthew-holtzem likes this.
  8. seffles

    seffles

    Joined:
    Oct 2, 2013
    Posts:
    27
    That sounds great, and thanks for the response. I have a couple of questions:
    1. Would this work as a stack (eg you can push 'flying' and it overrides 'walking' until you pop it), or does each action map have a simple priority? I can see uses for both, and in my case I'd prefer a stack for my current project.
    2. Can one layer (or action map, whichever) block a lower level one when enabled/pushed? In my flying/walking example, I'd want flying actions not to fire if the walking layer is enabled over it.