Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Discussion Input consumption is exactly what I needed until it wasn't

Discussion in 'Input System' started by sodarocketstudios, Feb 3, 2023.

  1. sodarocketstudios

    sodarocketstudios

    Joined:
    Jan 14, 2021
    Posts:
    21
    Context: I am creating an app that will allow users to place, move, and modify objects. Because of the nature of the app, I have undo and redo functionality setup with the standard ctrl+z and ctrl+shift+z shortcuts. This is typically an issue because when you press ctrl+shift+z, the input system will trigger any actions that use any combination of those keys. In my case both undo and redo are triggered when I just wanted redo. I was able to fix that problem by enabling Input Consumption in the project settings. But, as is typical, yesterday's solution is today's problem.

    Problem: Now I am trying to implement cancel functionality for the tools in the app. For example I have a move tool that allows you to grab an object and drag it by clicking and holding the mouse button and when you release the mouse button you drop the object in the new position (cancel would just send it back to where it was). this is where input consumption comes back to bite me. when you are holding an object (holding the mouse button) all other inputs are ignored meaning the only time you can cancel the use of a tool is when you aren't actively using the tool.

    My Potential Solution: The solution I have in my head is to disable input consumption and create some sort of shortcut manager that will be in charge of making sure that I don't call multiple shortcuts. Basically implementing my own form of input consumption for only certain actions (the shortcuts).

    If anybody has a better or simpler solution I would love to hear it.

    Edit: For anybody who finds this in the future. My problem was of my own making and not because of the input consumption setting. Only inputs with shared keys are consumed. i.e if I use ctrl+z and shift+ctrl+z, when I press shift+ctrl+z, Unity will ignore the fact that I pressed ctrl+z. But since I don't use escape and the mouse button together anywhere, the cancel action is still performed when the mouse button is held meaning the input is not consumed.
     
    Last edited: Feb 6, 2023
  2. rdjadu

    rdjadu

    Joined:
    May 9, 2022
    Posts:
    115
    What's the input that triggers canceling?

    Consumption should only affect related/overlapping inputs. Ctrl+Z and and Ctrl+Shift+Z are related/overlapping. Ctrl+Z and LMB are not. Ctrl+Z and anything else not using LMB should be unaffected while LMB is down and consumed by an action.
     
  3. sodarocketstudios

    sodarocketstudios

    Joined:
    Jan 14, 2021
    Posts:
    21
    I am using left mouse button for tool use and esc for cancel, but it is definitely still consuming the input. I used some Log statements to test it and the cancel is only called when I'm not pressing anything else. When I was reading about input consumption I got the same impression that it would only apply to actions with shared keys, but that doesn't seem to be the case unfortunately.
     
  4. sodarocketstudios

    sodarocketstudios

    Joined:
    Jan 14, 2021
    Posts:
    21
    Turns out it was just user error. My cancel input action was disabled when trying to test it. everything works how it is supposed to now.
     
    rdjadu likes this.