Hey there,
I’m working on a local multiplayer game with multiple controllers, and because of that, I cannot do a simple check like “Keyboard.current[KeyCode.Space].wasPressedThisFrame”.
My player object is going to end up a bit complex, plus I’m used to breaking up the scripts into different controllers. Anim/Input/OverallController etc. So I cant work just of the fired event, I would like to access a stored boolean for the pressed button action.
On my ActionObject, I have an event tied with the Jump button. And a boolean that stores a reference to the “IsKeyPressed” condition of that. I also managed to get it to work with FixedUpdate.
See here:
public class CharacterInputHandler : MonoBehaviour
{
public bool Jumped { get; set; }
public bool JumpedFixed { get; set; }
private bool jump = false;
public void EventJump(CallbackContext ctx)
{
//IsKeyDown() is an extanetion method I made, just check if InputActionPhase.Started
jump = ctx.IsKeyDown();
if (jump)
{
Jumped = true;
JumpedFixed = true;
}
}
private void Update()
{
if (Jumped) Jumped = false;
}
private void FixedUpdate()
{
if (JumpedFixed) JumpedFixed = false;
}
}
The issue is, it randomly stopped working for ages.
So I added a couple of extra booleans into my Update/FixedUpdate checks.
Like so…
bool jumpedFrameWaited = false;
private void FixedUpdate()
{
if (JumpedFixed)
{
if (jumpedFrameWaited)
{
JumpedFixed = false;
}
jumpedFrameWaited = true;
}
}
This worked for a bit, then started firing twice. As the other components were now ahead of the object in execution.
I don’t wanna mess with the execution order this early in development. Does anybody have any ideas?
I also tried the Tap interaction method but that is not accurate enough. A debug.log will show it stays true for too long, and at an inconsistent amount of frames so tweaking won’t work.
Any help would be greatly appreciated.