void FGameplayDebugger::OnLevelActorDeleted(AActor* InActor)
{
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
	if (!InActor)
	{
		return;
	}

	UWorld* World = InActor->GetWorld();
	if (!World)
	{
		return;
	}

	AGameplayDebuggingReplicator* Replicator = Cast<AGameplayDebuggingReplicator>(InActor);
	if (Replicator)
	{
		RemoveReplicator(World, Replicator);
	}
	else
	{
		APlayerController* PC = Cast<APlayerController>(InActor);
		if (PC)
		{
			// Take a copy because the destroy could lead to removes on the replicator array
			TArray<TWeakObjectPtr<AGameplayDebuggingReplicator>> ReplicatorsForWorld = GetAllReplicators(World);
			for (TWeakObjectPtr<AGameplayDebuggingReplicator> ReplicatorPtr : ReplicatorsForWorld)
			{
				AGameplayDebuggingReplicator* ReplicatorInWorld = ReplicatorPtr.Get();
				if (ReplicatorInWorld && ReplicatorInWorld->GetLocalPlayerOwner() == PC)
				{
					ReplicatorInWorld->Destroy();
					break;
				}
			}
		}
	}
#endif
}