thanks a lot, that helped immediately ![]()
None of the options above worked for me…
performed is triggered twice: on press AND release. Anybody finally found a real solution ? Or should I just go back to old unity input system ?
I had the same dream of it working similarly to the old system - so I wrote a wrapper generator thats a bit closer to home heh.
“performed is triggered twice: on press AND release”
Inside the performed callback, you can check the value of the button, if its 1 it was Pressed, 0 it was Released.
If you want to check for input every frame, then create a bool and call this function in Update()
Just remember to setup the actions as a new actions and enable it. Call this from awake
public static PlayerInput controls;
void SetUpActions()
{
controls = new PlayerInput();
controls.Enable();
}
Fire1 = Mathf.Abs(controls.Gameplay.Fire1.ReadValue<float>()) > 0;
Just set up an action in the inputactions thingy, give it a name, set a keybind to it and then call the above line. It will only return a positive value (hence the math abs). If it’s above 0, then your boolean will become true.
Now you can easily check from another script if this bool is true or false, and do whatever you want with that.
If you want to do the same for vertical and horizontal (old input style) then do this:
Vertical = controls.Gameplay.Movement.ReadValue<Vector2>().y;
Horizontal = controls.Gameplay.Movement.ReadValue<Vector2>().x;
Hope that helps!
Hi.
I know I am too late for the party but I was looking to solve the exact problem. I made a little workaround so maybe someone will benefit from it. (By the way, I use Unity Events for pooling)
private bool interact;
public void UpdateInteract(InputAction.CallbackContext context)
{
if (context.started)
{
interact = true;
}else if (context.canceled)
{
interact = false;
}
}
public bool GetInteract()
{
//return interact;
var temp = interact;
interact = false;
return temp;
}
The code by @JalalGurbanov won’t work for subsequent calls if you call the GetInteract function more than once in one frame.
If you are constrained to use the input in an Update/Tick function, instead of using events, because you need to support legacy content or whatever, I would recommend using .isTriggerd.
m_InputActions.PlayerControls.DPad.performed += ctx => { m_DPadInput = ctx.ReadValue<Vector2>(); };
public void Tick()
{
if (m_InputActions.PlayerControls.DPad.triggered == false) {
m_DPadInput = Vector2.zero;
}
}
In the example above Tick is called in an Update function.
If you are using a Monobehavior you could use LateUpdate() to reset the input.
I hope that helps someone and if you have a better solution please let me know.
for starters, this is superconfusing for a amatuer coder. the old input system was way easier to code. now im lost on a simple way to make a weapon build up its power, and release it when the player wants to fire.
pages of script needs to be filled for that to work. if i can understand what you guys are saying.
it was just getKeyDown / getKeyUp before. with a few extra lines for the function.
This isnt a good way to make it better.
Versatile yes, but superconfusing.
Well if you spent the time you spent here posting about the complexities of the new system on reading the manual, you probably would have came across with this page on it:
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Migration.html#unityengineinputgetbuttonhttpsdocsunity3dcomscriptreferenceinputgetbuttonhtml
í totaly missed that segment.
the wall of text just makes me sleepy and puts my head in a neglect state.
thanx for the help.
Ive read it, but have no idea to implement it into code.
I know how to press and hold to get a float value for the buildup. but no idea how to get the release function.
thanx anyway
I found an really easy solution by accident
I just use ScriptName.ActionMapsName.ActionsName. triggered inside an if. It works with Press Only, Release Only and Press & Release.
I made a really simple solution that I just felt like sharing even if it’s pretty bad. Just have the input set to Press and Release.
private bool buttonDown = false;
private void OnFire()
{
buttonDown = !buttonDown
}
So, just check the variable for the button down. I’m not really sure if there are any flaws with this solution, but I just started learning Unity a few days ago. ¯_(ツ)_/¯
Very very late to the party I know but I was here looking for an answer to something else and I noticed this well read post on a topic which seems to have been around since the the new input system was unveiled. So I just thought I’d add my solution to the “Actions as Buttons” idea.
I have a simple wrapper around an InputAction which provides 3 properties similar to the GetButton calls on the old system. These are IsActionTriggered, IsActionOngoing, IsActionEnded.
There is also an InputManager class which uses the InputActionWrapper and exposes the actions as named properties. So you can write code in your Update/FixedUpdate loop without having to use text strings like
if (inputManager.Jump.IsActionTriggered)
{
}
if (inputManager.Dash.IsActionEnded)
{
}
var mov = inputManager.Movement.ReadValue<Vector2();
You can still get at all the action functionality such as subscribe to events by using
inputManager.Fire.Action.started += FireAction_started;
I’ve attached a super simple small package which shows how to wire it all up to the PlayerInput component which the input system ships with. There’s also a QuantizeProcessor in there which makes Gamepad joysticks work like WASD on keyboards.
Hope it helps
Cheers
Mark
Where is the “Continuous” box?
Didn’t quite find the answer I was looking for here, and since this thread is a #1 hit on Bing, I’ll add my solution.
Goal was to:
- Use the new Input System
- Use the Send Messages behavior in the provided Player Input script
- Handle the Send Messages event on button down or button up (one call on new press or release)
- Know whether the button was pressed down or released.
Solution for me was:
-
Add the button to Master Input, with the option to trigger on press and release:
-
Add Unity’s Player Input component to my player object, with the desired behavior set up to Send Messages as shown:

-
Create a custom script (PlayerInputShip.cs) as seen above, and capture the messages.
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerInputShip : MonoBehaviour
{
private MasterInput actions;
private void Start()
{
PlayerInput input = this.GetComponent<PlayerInput>();
input.currentActionMap.Enable();
}
...
public void OnShootSecondary(InputValue inputValue)
{
if (inputValue.isPressed)
FireSuperGalacticDeathRay();
else
StopFirignSuperGalacticDeathRay();
}
}
Don’t know if this solution is obvious to everyone. Certainly wasn’t for me.
Heya, just to add this here as it’s relevant to the OP, as of 1.1-preview.2 (released last week) there are now new methods equivalent to GetButton, GetButtonUp, and GetButtonDown. Details in the docs here.
// GetButton("fire")
playerInput.actions["fire"].IsPressed()
// GetButtonDown("fire")
playerInput.actions["fire"].WasPressedThisFrame()
// GetButtonUp("fire")
playerInput.actions["fire"].WasReleasedThisFrame()
This can be used with any action (i.e. not necessary to have it set to Button type). For actions with value types other than float, this goes purely by “magnitude of actuation” which may or may not make sense for your particular case.
Also, the behavior of Button type actions has been adjusted to properly take press points into account. The behavior of Button type actions without any added interactions is now equivalent to having added a Press interaction before with it set to “Press Only”.
Finally, release thresholds have been added to offset release points slightly from press points. This makes controls such as gamepads a little more stable around the press point.
@Rene-Damm I’m trying to do a really simply thing:
void Start()
{
_inputs = new PlayerInputs();
_inputs.Enable();
}
void Update()
{
Debug.Log($"IsFiring: {_inputs.Player.Fire.activeControl.IsPressed()}");
}
However activeControl is null when fire is not being pressed. What is your intended way of doing this? I can’t imagine I’m meant to check if it is null first. Have I missed something?
p.s. I don’t want to use events, I just want to poll.
_inputs.Player.Fire.activeControl?.IsPressed()
?? O.o Still ugly.
This is working for me:
characterActions.Gameplay.Jump.IsPressed()
See @lightbug14 's reply.



