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"));
}