Destroying an Actor after a delay using SetLifeSpan
Let's look at how we can destroy an Actor
.
- Create a new C++ class using the wizard. Select
Actor
as your base class. - In the implementation of
Actor
, add the following code to the BeginPlay
function: - 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 itself.
- We insert our code into the
BeginPlay
function so that it executes when the game starts. 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.