Let's look at how we can destroy an Actor.
Destroying an Actor after a delay using SetLifeSpan
How to do it...
- If you haven't already, create a new C++ class using the wizard. Select Actor as your base class. In our case, I will reuse the AWarrior class we created previously in this chapter.
- In the implementation of Actor, add the following code to the BeginPlay function:
// Called when the game starts or when spawned
void AWarrior::BeginPlay()
{
Super::BeginPlay();
// Will destroy this object in 10 seconds
SetLifeSpan(10);
}
- Drag a copy of your custom Actor into the viewport within the Editor.
- Play your level and look at the Outliner to verify that your Actor instance disappears after 10 seconds, having destroyed...