- In the DelegateListener class, add the following overridden function declaration:
UFUNCTION()
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
- Implement the function like this:
void ADelegateListener::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
Super::EndPlay(EndPlayReason);
UWorld* TheWorld = GetWorld();
if (TheWorld != nullptr)
{
AGameModeBase* GameMode =
UGameplayStatics::GetGameMode(TheWorld);
AChapter_05GameModeBase * MyGameMode =
Cast<AChapter_05GameModeBase>(GameMode);
if (MyGameMode != nullptr)
{
MyGameMode->MyStandardDelegate.Unbind();
}
}
}