This recipe will reuse the GameMode
from the previous recipe, so you should complete it first.
Make the following changes to the
GameMode
declaration:UPROPERTY() AMyFirstActor* SpawnedActor; UFUNCTION() void DestroyActorFunction();
Add
#include "MyFirstActor.h"
to the implementation file's includes.Assign the results of
SpawnActor
to the newSpawnedActor
variable:SpawnedActor = GetWorld()->SpawnActor<AMyFirstActor> (AMyFirstActor::StaticClass(), SpawnLocation);
Add the following to the end of the
BeginPlay
function:FTimerHandle Timer; GetWorldTimerManager().SetTimer(Timer, this, &AUE4CookbookGameMode::DestroyActorFunction, 10);
Lastly, implement
DestroyActorFunction
:void AUE4CookbookGameMode::DestroyActorFunction() { if (SpawnedActor != nullptr) { SpawnedActor->Destroy(); } }
Load the level you created in the previous recipe, which had the game mode set to your custom class.