I’m trying to switch from the old the new input system, and I’m not a big fan of the action/callback style. I’m using a multi state controller using an enum, so I don’t want to call a function whenever a button is pressed, but rather depending on the state he is in. I used to just use getbutton and the like, and it seems the new input system has similar functions like ispressed but all the examples use it by checking directly on the device ( is the ‘space’ key pressed ? ) And not the action map set up by the dev (is the jump button pressed ?)
Okay so I figured out that you can use ‘.triggered’ to check if the action was performed this frame… That’s progress, but I still can’t test wether the key was being held or released this frame… I have spent so much time on this new input system to try and understand how to access the basic functions the old system had, it’s so frustrating…
The polling API for InputActions doesn’t make this one nice ATM. Closest you can get ATM for both press and release detection is to have a Press interaction on the binding and set it to “Press and Release” and do something like
var wasPressed = action.triggered && action.ReadValue<float>() > 0;
var wasReleased = action.triggered && action.ReadValue<float>() == default;
Not great.
The polling API still needs some more fleshing out. Adding IsPressed(), WasPressedThisFrame(), and WasReleasedThisFrame() methods to InputAction is in the works.
I see, thank you, I had not figured out combining it with the read value, so I created two actions with the same keys, one for the pressing and one for the releasing. But to add a “is pressed” functionality I still need to create a bool that I toggle based on those inputs right ?
That makes for some very complex code for simple stuff, I kinda regret switching, but I’ll stick with it for now, IsPressed(), WasPressedThisFrame(), and WasReleasedThisFrame() should allow us to get the same functionality as the old system when they get there.
With the Press interaction on there and it set to “Press and Release”, there’s no need for the extra bool. The action performing with a value of 1 implies “pressed this frame” and it performing with a value of 0 implies “released this frame”.
I do have another question with the Input system, I’m using cursor warping to allow for gamepad users to select and press buttons in a menu, but it seems the warped cursor doesn’t trigger events like ‘onPointerEnter’ and the like, which kind of makes it useless ? Unless there is setting I’m missing or a way to manually raycast from the mouse, but I can’t find information on this…
Maybe this isn’t the place where I should ask that, anyway thanks for the help.
Are you using VirtualMouseInput from the GamepadMouseCursor sample? UI input should work fine with it.
Overall, if UI input is set up with InputSystemUIInputModule and the Mouse device the warping happens on is tied to the “point” action of the input module, then warping of the cursor should come through just fine (it’ll be a frame late but should come through).
“VirtualMouseInput from the GamepadMouseCursor sample” - I am not sure I understand what that is, and I can’t find docs with a google search. But I am using the InputSystemUIInputModule with the default settings for now.
The warping does come through and works as expected, but when the cursor is over a button it does not highlight like it does with the mouse.
As I tested, “Press and Release” interaction is required only for wasReleasedThisFrame functionality. isPressed and wasPressedThisFrame work out of the box.
Its fine that there is finally going on some change about Input in Unity, but I wish there was an out of the box setup
mimic the old Input where you have gravity for axes and that stuff, this would also help to migrate very fast , the new Input system is rather huge and the learning curve is rather steep.
“Clever is the enemy of Clear”…
I created a paid asset that actually helps with the conversion of old Input Manager to new Input System. It let’s you write code exactly the same as you’re used to writing but leveraging the new Input System. There is a link in my signature. Basically it wraps the new Input System and tries to replicate the simplicity of the old system as much as possible. With the asset you can use a script written for the old Input Manager and make no code changes to it, replicate the Input Manager Settings in an Input Action Asset(included in the asset), and your code will just work with the new system. Though to your point Karsten, it doesn’t provide the really advanced stuff that the new Input System provides like Hold Interactions and Tap Interactions and stuff like that. It does make your code really clean though since you don’t have to deal with any callback methods or the like.
I’ve just switched to it because of some packaged I wanna try, and I am shocked how you can badly design it , it’s learning curve is so high and setup everything is on some other places, it’s garbage , and then I find out it’s not even easily backwards compatible.
Nice, and “Press and Release” interaction is not needed anymore for “WasReleasedThisFrame” to work.
Though for some weird reason the package manager UI was not prompting me to update to the new version (I was still in 1.0.2), but was able to update after manually changing the version number in my manifest.json.
When I go to the package manager, then I can’t update the Input System to version 1.1, since it is marked as fully updated, even though it’s just 1.0.2. Any help? I would really like to have the action.IsPressed() function.
ps: I tried the trick that SamMacedo mentioned (manually change the version in manifest.json), but it didn’t work for me.