hey guys i’m trying to play a walking sound when the player is pressing the forward button I’m using spawnsound2D function to do so but there’s a problem and that is instead of playing the sound and waiting for it to finish the function is being called everyframe so it makes a horrible noise. here is the code
void AFirstPerson::MoveForward(float Amount)
{
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation = FRotator(0, Rotation.Yaw, 0);
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(Direction, Amount);
if (Amount != 0.0f)
{
PlaySound = true;
if (WalkingSound && PlaySound)
{
UGameplayStatics::SpawnSound2D(this, WalkingSound);
UE_LOG(LogTemp, Warning, TEXT(“Playing Sound”));
}
}
if (Amount == 0.0f)
{
PlaySound = false;
UE_LOG(LogTemp, Warning, TEXT(“Stopping Sound”));
}
}