Sometimes, it is necessary to remove a delegate binding. This is like setting a function pointer to nullptr
so that it no longer references an object that has been deleted.
You'll need to follow the previous recipe in order for you to have a delegate to unregister.
In
DelegateListener
, add the following overridden function declaration:UFUNCTION() virtual void EndPlay(constEEndPlayReason::Type EndPlayReason) override;
Implement the function like this:
void ADelegateListener::EndPlay(constEEndPlayReason::Type EndPlayReason) { Super::EndPlay(EndPlayReason); UWorld* TheWorld = GetWorld(); if (TheWorld != nullptr) { AGameMode* GameMode = UGameplayStatics::GetGameMode(TheWorld); AUE4CookbookGameMode * MyGameMode = Cast<AUE4CookbookGameMode>(GameMode); if (MyGameMode != nullptr) { MyGameMode->MyStandardDelegate.Unbind(); } } }