How does OnAudioFinished delegate work?

I notice that my delegate is not called untill I stop the game. On shutdown the delegate is called once. What I expect to happen is that when a sound is fully played, then this delegate is called. Am I misunderstanding OnAudioFinished or is there a mistake in my code?

At the moment the sounds (EngineAcceleration and EngineIdle) are looped over and over, which is what I want; could the be interfering with OnAudioFinished?

Header:

#pragma once

#include "CoreMinimal.h"
#include "Components/AudioComponent.h"
#include "TankAudioComponent.generated.h"

class ATank;

/**
 * 
 */
UCLASS()
class TANKIONLINEREWORK_API UTankAudioComponent : public UAudioComponent
{
	GENERATED_BODY()

public:
	UTankAudioComponent();

	void Initialize(ATank* ParentTank);
protected:
	virtual void BeginPlay() override;
	
public:
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

	UFUNCTION()
	void FinishedTest();

Source:

#include "TankAudioComponent.h"

#include "Tank.h"

UTankAudioComponent::UTankAudioComponent()
{
	PrimaryComponentTick.bCanEverTick = true;
}

void UTankAudioComponent::BeginPlay()
{
	Super::BeginPlay();

	OnAudioFinished.AddDynamic(this, &UTankAudioComponent::FinishedTest);
}

void UTankAudioComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	if (!Tank) return;
	
	if (Tank->IsDriving())
	{
		if (bIdle || !IsPlaying())
		{
			Stop();
			SetSound(EngineAcceleration);
			Play();
			bIdle = false;
		}
	}
	else
	{
		if (!bIdle || !IsPlaying())
		{
			Stop();
			SetSound(EngineIdle);
			Play();
			bIdle = true;
		}
	}
}

void UTankAudioComponent::FinishedTest()
{
	UE_LOG(LogTemp, Warning, TEXT("hi"));
}

Hello! OnAudioFinished delegate is called when Audio is stopped, removed from Audio list or completed (make it to the end and stop). In case of loop nothing of that happens. I search for delegate you need, but not found any at the moment

Thank you, looping is the issue. The acceleration actually does not have to loop, so disabling the loop on it makes the delegate work. Now I can finish the audio of the tank. :slight_smile:

Looping was enabled on the SoundWave assets. As looping does not fire the OnAudioFinished event, my delegates did not get called.