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

Question Allowing specific Bindings input only when other keys are pressed

Discussion in 'Input System' started by fherbst, Jul 19, 2021.

  1. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    I'm trying to get a specific setup to work but ran out of ideas on how to build this properly using the new input system.

    Scenario:
    Building a typical "flight cam". There are multiple input sources that could all be active simultaneously at any given point, e.g. a Space Mouse (a device that reports a 3D Vector axis for both translation and rotation), a mouse, a keyboard.

    So far I set this up as a action map like this:
    upload_2021-7-19_14-28-48.png

    TranslationVec and RotationVec are custom Vector3 composites (not sure why those don't ship out of the box).
    Translation works fine (just keyboard keys).
    Rotation uses a mix of keyboard keys and mouse axis to work:

    upload_2021-7-19_14-29-41.png

    The problem is that for rotation, I only want mouse deltas to drive that when also the right mouse button is pressed. So, I basically need to prevent mouse motion when the right mouse button is NOT pressed, but I don't find a "good" way to do this that lets me abstract that away from the action map and avoid adding such logic to the code (where I'd only want to see "translation performed" and "rotation performed" events and not have to think about what drives those, which I think is a design goal of the Input System).

    Things I've tried:
    1. adding a custom
      Interaction
      that only lets data through when a specific button is pressed. Seems that's not possible (or at least hard) because the public fields on this can only be "PrimitiveType"s, so basically floats. I can't make a
      public InputAction
      or
      public string
      . I could probably hard code the button name to filter by that but that seems wrong.
    2. adding a custom Processor that multiplies by the state of that button. I can't even get that to show up in the action editor but from the code it looks like that would have the same issue of not allowing InputAction/string fields.
    3. splitting this in two action maps, "Space Mouse" and "Keyboard", and adding an extra action for "CameraCanMove", and chaining the Rotate action so that it only gets activated once CameraCanMove is performed/true. This would require me to have the SpaceMouse one set to "always true" which doesn't seem to exist out-of-the-box and make problems with initialisation (I'd have to make a custom device just to set the bool at some point)
    So, the next would be "giving up" and adding device-specific logic in code, which I'd certainly like to avoid (one goal here is to understand the "right" way).

    Is there a better way to approach this?

    EDIT: Found the "ButtonWithOneModifier" composite action and will try to understand that next. Not sure if that is the right approach, as it feels like that path still would require writing lots of custom composites to get desired behaviour.

    EDIT 2: No luck, while I found the "Binding with One Modifier" I seem to be unable to actually bind this to either the action or another binding in the same input asset.

    upload_2021-7-19_23-56-6.png

    I tried several different ways to write/the binding path (*/MySpecialBinding, Fly/RotationBase/MySpecialBinding, ...) but I always just get NullRefs:
    upload_2021-7-19_23-58-15.png
     
    Last edited: Jul 19, 2021