AudioComponent

Hi every one,

I am trying to spawn the sound cube inside audiocomponent, but the issue the previous sound is overlapping with a new one. So when I pressed P TurnONTheCar() will be running, but in Tick() function where the overlapping is happening, despite spawning the sound. Thank you in advance. here is the code:

void AControllingCar_Cars::Tick(float Delta)
{
Super::Tick(Delta);

if (IsTheCarWorking )
{





		if(GetVehicleMovement()->GetForwardSpeed()==0 )
		{


			PlayingTheSound->Play();
			
				
			PlayingTheSound->SetSound(CountiniouingEngineSound);
		}

}

}

void AControllingCar_Cars::TurnONTheCar()
{

PlayingTheSound->SetSound(StartingEngineSound);

PlayingTheSound->Play();

GetWorld()->GetTimerManager().SetTimer(Timer, this, &AControllingCar_Cars::KeepTheEngineOnTurning, 
     StartingEngineSound->GetDuration(), false);

}

void AControllingCar_Cars::KeepTheEngineOnTurning()
{

   PlayingTheSound = UGameplayStatics::SpawnSound2D(this, StartingEngineSound);
PlayingTheSound->Stop();
EngineBoostingDone = true;
IsTheCarWorking = true;

}

If IsTheCarWorking is true and GetVehicleMovement is 0, the sound will play and set the sound every single tick as long as those conditions are met, it doesn’t matter if something else is playing or not. That’s why it sounds like it’s overlapping. If you only want it to play once, try not putting your engine running sound in tick, instead call a different function that can only run one time. For an engine sound, you’d want a loop that plays as long as the car is on. Set a function that makes a looping engine sound when the car is running, and stops when it’s off.

Also make sure in your other functions to stop playing them when something else is about to play.

For bonus you can change the pitch of the loop when the car is running faster or slower to give a real engine feel!