Let me give u an example. It just cost me lots of time to find a way to make my c++ callback work just like BP:
(Be careful about the event mask, u should set it to the event type u want to listen, set to 0 will miss all events. And also have a notice on the UFUNCTION macro of the callback, it's for dynamic delegate.)
class ATest : public AActor
{
public:
FOnAkPostEventCallback OnAkPostEventDelegate;
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
UFUNCTION()
void OnAkPostEventCallback(EAkCallbackType CallbackType, UAkCallbackInfo* CallbackInfo);
void LetWwiseSpeakSomething(AActor* Actor, UAkAudioEvent* AkEvent);
};
void ATest::BeginPlay()
{
OnAkPostEventDelegate.BindDynamic(this, &ATest::OnAkPostEventCallback);
// other codes;
}
void ATest::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
OnAkPostEventDelegate.Clear();
// other codes;
}
inline void ATest::LetWwiseSpeakSomething(AActor* Actor, UAkAudioEvent* AkEvent)
{
UAkGameplayStatics::PostEvent(AkEvent, Actor, AK_EndOfEvent, OnAkPostEventDelegate);
}