Destroying an Actor after a delay using SetLifeSpan

Let's look at how we can destroy an Actor.

How to do it...

  1. Create a new C++ class using the wizard. Select Actor as your base class.
  2. In the implementation of Actor, add the following code to the BeginPlay function:
    SetLifeSpan(10);
  3. Drag a copy of your custom Actor into the viewport within the Editor.
  4. Play your level, and look at the Outliner to verify that your Actor instance disappears after 10 seconds, having destroyed itself.

How it works...

  1. We insert our code into the BeginPlay function so that it executes when the game starts.
  2. SetLifeSpan(10);: The SetLifeSpan function allows us to specify a duration in seconds, after which the Actor calls its own Destroy() method.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.65.61