March 2019
Intermediate to advanced
708 pages
17h 9m
English
We declare a UPROPERTY to store our spawned Actor instance, and a custom function so that we can call Destroy() on a timer:
UPROPERTY() AMyFirstActor* SpawnedActor; UFUNCTION() void DestroyActorFunction();
In BeginPlay, we assign the spawned Actor to our new UPROPERTY:
SpawnedActor = GetWorld()->SpawnActor<AMyFirstActor> (AMyFirstActor::StaticClass(), SpawnLocation);
We then declare a TimerHandle object and pass it to GetWorldTimerManager::SetTimer. SetTimer calls DestroyActorFunction on the object that was pointed to by this pointer after 10 seconds. SetTimer returns an object – a handle – to allow us to cancel the timer if necessary. The SetTimer function takes the TimerHandle object in as a reference parameter, and so ...
Read now
Unlock full access