In Unity, my joystick button only works a few times, why?

My part of the input code looks like this:

void Update()
{
y_input = Input.GetButtonUp(StaticStrings.Y);

delta = Time.fixedDeltaTime;
states.Tick(delta);
ResetInputNStates();
}

void GetInput()
{
vertical = Input.GetAxis(StaticStrings.Vertical);
horizontal = Input.GetAxis(StaticStrings.Horizontal);
b_input = Input.GetButton(StaticStrings.B);
a_input = Input.GetButton(StaticStrings.A);
y_input = Input.GetButtonUp(StaticStrings.Y);
x_input = Input.GetButton(StaticStrings.X);
rt_input = Input.GetButton(StaticStrings.RT);
rt_axis = Input.GetAxis(StaticStrings.RT);

if (rt_axis != 0)
rt_input = true;

lt_input = Input.GetButton(StaticStrings.LT);
lt_axis = Input.GetAxis(StaticStrings.LT);

if (lt_axis != 0)
lt_input = true;

rb_input = Input.GetButton(StaticStrings.RB);
lb_input = Input.GetButton(StaticStrings.LB);

rightAxis_down = Input.GetButtonUp(StaticStrings.L) || Input.GetKeyUp(KeyCode.T);

if (b_input)
b_timer += delta;

d_up = Input.GetKeyUp(KeyCode.Alpha1) || d_y > 0;
d_down = Input.GetKeyUp(KeyCode.Alpha2) || d_y < 0;
d_left = Input.GetKeyUp(KeyCode.Alpha3) || d_x < 0;
d_right = Input.GetKeyUp(KeyCode.Alpha4) || d_x > 0;
}


The problem is that my Y button is connected with the function of changing from one hand weapon to two hand weapon, but the Y button only works a few times in game!

e.g., I have to press about 3 times then it works.

How do I solve this?

• I'm unable to reproduce the problem you describe with the code you're shown here. Can you create a new project and add to it the bare minimum scripts & components needed to display this issue, and share with us the complete recipe for recreating it? – DMGregory Jan 15 at 18:49
• Is it your intention to set y_input in both Update and GetInput? – Tashus Jan 15 at 20:43
• Are you by any chance querying the input from FixedUpdates elsewhere in the game ? FixedUpdate is often called more frequently than Update. It can be called multiple times per frame, if the frame rate is low and it may not be called between frames at all if the frame rate is high. – Omar Guendeli Jan 16 at 6:08
• Where do you call GetInput()? I guess it's a race condition between GetInput() and update() – JeffUK Jan 16 at 13:59
• Thank you guys for all the answers ! It's the problem with Update & FixedUpdate that I didn't think of. – Young Gilgamesh Jan 17 at 7:51