Polling API
I need to read an input after physics has been processed (need to know if the character is grounded) and with the current event based API this quickly becomes a hassle.
I have to listen to the "performed" events that happen either before FixedUpdate or Update (depending on your configurations) and store in a boolean whether or not an event happened during a certain frame to later use that variable inside my Update(). Finally, I have to setup a coroutine with WaitForEndOfFrame to reset the boolean.
Are there any alternatives? I think this is a pretty common use case so I am probably missing something...
You might have better luck to ask questions in the forum: https://forum.unity.com/forums/new-input-system.103/
Thank you @JiaUnity !
I asked in the forum and people apparently don't know of an immediate mode API for the new input system. The thread progresses slowly as it seems that not many people have adopted the new input system so far...
The workaround I am currently using is dealing directly with raw input using the Gamepad and Keyboard classes but I think that the best way would be to have a flexible API for InputActions. Just giving the option to check if an action was performed on the current frame would be great!
A polling API for actions is in the works. The current design is
// Has the action been performed in the current update?
bool InputAction.triggered;
// Read the value the action was last performed with. Returns default value if action is canceled or not yet started.
InputAction.ReadValue<T>();
So, "jump if grounded" could become something like
if (m_MyControls.gameplay.jump.triggered && CharacterIsGrounded())
Jump();
Is this what you're looking for?
Yeah! That's exactly it! I saw some mentions in the documentation of a wasPerformedThisFrame but couldn't find it anymore.
I'll try it out :)
Wait, just to be clear, these two APIs aren't in there yet. It's in the works, though. Have hope it'll land before 1.0.
Oh, ok! Sorry, I was so excited that I didn't pay attention the "in the works" part of your post hahaha
Anyway, good to hear that this API will be available in the future :)
Well, as a suggestion, I would probably name these methods as they are currently named for the devices. So:
wasPressedThisFramewasReleasedThisFramepressed- ...
The polling API has landed on the develop branch with #722 and should be in the next package.
0.9.0-preview is out and contains the aforementioned changes.