[C++] Combo Attack Issue – Second Attack Executes Automatically Without Input

Hi everyone,

I’m working on a combo attack system using animation montages, and I’m running into a problem where the second attack in the sequence executes automatically after the first attack, without any additional input from the player. However, the third attack behaves correctly — it only triggers if I press the attack button again.

Here’s the full relevant code for reference:

cpp

CopiarEditar

void ATraining2Character::SwordFirstComboAttack()
{
	UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();

	if (AnimInstance && SwordFirstAttack)
	{
		if (!isAttacking)
		{
			AnimInstance->Montage_Play(SwordFirstAttack);
			AttackIndex = 1;
			isAttacking = true;
		}
	}
}

void ATraining2Character::SwordSecondComboAttack()
{
	UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();

	if (AnimInstance && SwordSecondAttack)
	{
		if (!isAttacking)
		{
			AnimInstance->Montage_Play(SwordSecondAttack);
			AttackIndex = 2;
			isAttacking = true;
		}
	}
}

void ATraining2Character::SwordThirdComboAttack()
{
	UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();

	if (AnimInstance && SwordThirdAttack)
	{
		if (!isAttacking)
		{
			AnimInstance->Montage_Play(SwordThirdAttack);
			AttackIndex = 3;
			isAttacking = true;
		}
	}
}

void ATraining2Character::SwordAttack()
{
	if (isAttacking == true)
	{
		if (!SaveAttack)
		{
			SaveAttack = true;
		}
	}
	else
	{
		SaveAttack = false;
		SwitchComboAttack();
	}
}

void ATraining2Character::SwordAttackComboManage()
{
	if (isAttacking)
	{
		isAttacking = false;
	}
	if (SaveAttack == true)
	{
		SaveAttack = false;
		SwitchComboAttack();
	}
	else
	{
		SwordAttackReturnToZero();
	}
}

void ATraining2Character::SwitchComboAttack()
{
	switch (AttackIndex)
	{
	case 0: SwordFirstComboAttack(); break;
	case 1: SwordSecondComboAttack(); break;
	case 2: SwordThirdComboAttack(); break;
	default: break;
	}
}

void ATraining2Character::SwordAttackReturnToZero()
{
	isAttacking = false;
	AttackIndex = 0;
}

:magnifying_glass_tilted_left: What’s going wrong:

  • After calling SwordFirstComboAttack(), the first montage plays correctly.
  • However, when the animation finishes and SwordAttackComboManage() is called (via AnimNotify), the second combo triggers automatically, even if I haven’t clicked the attack button again.
  • The third attack works as expected: it only plays when I click again.

I think the issue might be related to the SaveAttack flag being set too early (e.g. from a single click during the first attack), but I haven’t been able to solve it yet.

Has anyone else run into this or know a clean way to ensure input is only saved within a certain window during the attack animation?

Thanks in advance!