2

I'm learning the new input system and I'm looking for something like this:

if(anyInputActionIsPerformed)
{
return thatInputAction;
}

What I'm trying to do is to get the name of the current input action so I can save it in my input buffer for triggering something later.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Truofan
  • 21
  • 2
  • Ok guys I've figured it out from the documentation, I found the "InputActionMap.actionTriggered" event which is perfect enough for me so if anyone else bumped into a similar problem, you might wanna try this. – Truofan May 21 '22 at 08:04

1 Answers1

1

You can use IsPressed directly:

_controls.ActionMap.Action.IsPressed()

For Example:

private PlayerControls _controls;
public void Start()
{
    _controls = new PlayerControls();
    _controls.Enable();
}
void Update()
{
    if (_controls.GamePlay.TakeItem.IsPressed()) Debug.Log("Is Pressed!");
}

GamePlay/TakeItem/E


Single Action Map Event Triggered

Controls.GamePlay.Get().actionTriggered += ctx => Debug.Log(ctx.action);

Single Action Map Direct Triggered

foreach (var _inputAction in Controls.GamePlay.Get().actions.Where(_inputAction => _inputAction.triggered))
{
    Debug.Log(_inputAction);
}

Total Action Map Triggered

foreach (var _inputAction in Controls.asset.actionMaps.SelectMany(_assetActionMap => _assetActionMap.actions.Where(_inputAction => _inputAction.triggered)))
{
    Debug.Log(_inputAction);
}
KiynL
  • 4,097
  • 2
  • 16
  • 34
  • 1
    I've figured it out myself and this is not what I asked, but thank you though. – Truofan May 21 '22 at 07:56
  • @Truofan ops sorry. I read your question again. I added three methods to the answer and hope it is useful. (Note: the new input system with the event-oriented structure actually prevents over-performing. So the old way of getting the key is not very optimized.) – KiynL May 21 '22 at 08:43
  • 1
    Thank you again, I'm using the actionTriggered event now and the rest two still look like some higher dimension alien language to me now lol, Guess it's better to stick with code that is my level. – Truofan May 23 '22 at 01:33
  • @Truofan No, you are using the right way. Unfortunately, I misunderstood your question the first time, otherwise I could have helped better. – KiynL May 23 '22 at 04:54