- Home /
New Input System 'Started' and 'Performed' actions fire at the same time?
Hey guys,
So, I'm writing a simple 2D player script with an input manager. I'm trying to have a "Started" action that fires an OnMoveStart event, and a "Performed" action that fires an OnMoveEnd event. I'm doing this so I can continuously call the OnMoveStart method via a boolean in Update so the player can hold down the forward key and stay moving. The problem seems to be that both started and performed actions are firing simultaneously, as noted by a Debug.Log. I thought 'Started' happened when the key was initially pressed, and 'Performed' happened when the key was released? Is this not the case? Is there something else I'm doing wrong? Thanks for any help. Here's the Input Manager:
.
public class InputManager : MonoBehaviour
{
public static Controls inputActionAsset;
[SerializeField] public PlayerController Player;
private void OnEnable()
{
inputActionAsset = new Controls();
inputActionAsset.Player.Move.started += Player.OnMoveStart;
inputActionAsset.Player.Move.performed += Player.OnMoveEnd;
inputActionAsset.Enable();
}
private void Update()
{
if (Player.moving)
{
Player.rb.velocity = new Vector2(Player.moveSpeed * Player.multiplier, 0);
}
}
.
and the PlayerController script:
.
public class PlayerController : MonoBehaviour
{
public Rigidbody2D rb;
[SerializeField] public int moveSpeed;
public float multiplier;
public bool moving;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
//if the player starts the action, set the move bool to true
//if the player performs the action, set the move bool to false
//this move bool calls the move action in update, so if it's true, it'll keep firing
public void OnMoveStart(InputAction.CallbackContext context)
{
multiplier = InputManager.inputActionAsset.Player.Move.ReadValue<float>();
rb.velocity = new Vector2(moveSpeed * multiplier, 0);
moving = true;
Debug.Log(moving.ToString());
}
public void OnMoveEnd(InputAction.CallbackContext context)
{
moving = false;
Debug.Log(moving.ToString());
}
}
.
there's some ugly code in here I plan on changing, like caching vectors and stuff but I'm just trying to get it to work for now.
Answer by JethRow · Nov 25, 2021 at 06:18 PM
Hello, I can tell you what i found out about those 2 and it has been bothering me alot too! when you are using joysticks , as i did, and for example setting "Started" for your axises for example left joystick stick, i was getting values depending on how fast i moved joystick stick, as soon as updates start it takes in that one value and it just keeps that value untill you stop interacting with stick and the "Canceled" would be called , and for "Performed" i had results that i got a value that changed while update was running depending on how much i pushed the stick, so for example on Mouse axis X for "Started" if you moved your mouse slowly to the left you would get -0.08 and if it was faster it would be up to -1 depending how fast ur hand is, and for "Performed" you would get nice values across as long cancelled is not called , i hope this helps you!
also both Started and Performed are started when the key is pressed, the difference is Started takes first value it gets from the update or whatever you are using, and performed updates those values, in order , What u think that Performed is doing is what Canceled is doing and that is what happens when u stop pressing the button, usually something like
if (context.canceled)
{
Vertical = 0f;
}
Cheers!