Search Unity

How do I check if an action is performed?

Discussion in 'Input System' started by PixelDough, Jul 15, 2019.

  1. PixelDough

    PixelDough

    Joined:
    Apr 27, 2018
    Posts:
    56
    The ability to use C# Delegate Actions with this input system is really great, don't get me wrong, but is there any way I can simply check if an action is performed or not (as in, the bool value of an input action)? I have an interaction system set up, and with the old input system, I just checked if the appropriate button was pressed in order to interact with what the player was looking at.

    The new input system makes it so much easier to create actions with support for multiple bindings and gamepads, but it makes it much harder to incorporate into anything other than a few simple uses in my opinion. With my interaction system, I cannot seem to find a way to just say
    Code (CSharp):
    1. if (controls.Player.Interact == true)
    2. {
    3. // do interaction code...
    4. }
    If there's any way to achieve this effect, I think many other people would benefit from knowing how to do this. I'm currently considering returning to the older, more frustrating input system, as it seems it seems to have fundamental input system functionality.
     
  2. - I think the more better solution: you have a boolean which is true when the player is looking at the object in question (or in the trigger or whatever, you know how it works), in the delegate of the Interact.performed you can check this boolean and act accordingly
    - second method:
    Code (CSharp):
    1. [...]
    2. bool wasInteractionPressed = false;
    3. [...]
    4. controls.GamePlay.Interact.performed += ctx => wasInteractionPressed = true;
    5. controls.GamePlay.Interact.cancelled += ctx => wasInteractionPressed = false;
    6. [...]
    - third method: use the if(InputSystem.GetDevice<Keyboard>().aKey.wasReleasedThisFrame) {} // obviously you need to replace the aKey with something you desire, and this is the outdated way we used the old input system before
     
    NeatWolf likes this.