I have spent more hours than I care to admit on this problem. Sigh.
I have this script attached to my root node (CharacterBody2D):
public partial class Player : CharacterBody2D
{
[Export]
public bool isAttacking = false;
[Export]
public bool hasQueuedAttack = false;
// more stuff
}
And I have this method in a child node which is a Node2D called InputController:
public override void _Input(InputEvent @event)
{
if (Input.IsActionPressed("Attack") && player.Can("Attack"))
{
if (player.isAttacking)
{
player.hasQueuedAttack = true;
}
else
{
player.isAttacking = true;
}
return;
}
// More stuff
}
I am running GD.Print(player.hasQueuedAttack) at the end of every call of _PhysicsProcess to see what’s happening, and I noticed that it becomes true on the frame where I press attack, but then it becomes false on the frame immediately after.
I swear to god this is the only place where hasQueuedAttack is being written (besides being initialized as false in the Player class), as shown in the picture attached:
I am using a state machine, but it only sets hasQueuedAttack in the RESET node, and the variable is being set to false long before that.
If you’re wondering about the player.Can method, here it is:
public bool Can(string action)
{
if (isImpaired)
{
return false;
}
bool isAble = action switch
{
"Attack" => !isParrying && !isJumping && !isCasting && !isDashing,
"Parry" => !isAttacking && !isJumping && !isCasting && !isDashing,
"Jump" => !isAttacking && !isParrying && !isCasting && !isJumping && !isDashing,
"Cast" => !isAttacking && !isParrying && !isJumping && !isDashing && !spellsAreOnCooldown,
"Move" => !isAttacking && !isParrying && !isCasting && !isDashing,
"Dash" => !isAttacking && !isParrying && !isCasting && !isDashing,
_ => false
};
return action == "Move" ? isAble : isAble && IsOnFloor();
}
I am out of ideas. I have triple checked everything and tried many things, nothing worked. At this point I desperately need an input (no pun intended).
Thanks in advance.