How to do it...

  1. 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.
  2. 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);

}
  1. Drag a copy of your custom Actor into the viewport within the Editor.
  2. Play your level and look at the Outliner to verify that your Actor instance disappears after 10 seconds, having destroyed itself.