MyClass was just a example name. Meaning you change that to whatever the name of the class you are using this in. So if you were using this in a actor class you had created, say named “MyCustomActor”. Then the code would be something like:
void AMyCustomActor::RegisterSpawnHandler(UWorld* InWorld)
{
FOnActorSpawned::FDelegate ActorSpawnedDelegate = FOnActorSpawned::FDelegate::CreateUObject(this, &AMyCustomActor::OnActorSpawned);
InWorld->AddOnActorSpawnedHandler(ActorSpawnedDelegate);
}
void AMyCustomActor::OnActorSpawned(AActor* InActor)
{
//a new actor (InActor) has been spawned in the world.
}
Then once you have called RegisterSpawnHandler (maybe from beginplay), every time a new actor is pawned in the world that Actor is in then OnActorSpawned should be called with the param being the actor that was spawned. Also as I said before, you also want to save the FOnActorSpawned::FDelegate ActorSpawnedDelegate as a class variable, so that when your actor instance is deleted you can remove the delegate.