destorying multiple spawned actors, with delay

Basically player middle mouse buttons it creates a fire particle from blueprint, delays 5 seconds then destroys the spawned actor. That works perfectly fine if you just create one. If I create multiple ones before the delay is up. The SpawnActor sets the destroy Actor to the last one created, and then the destroy fires from the delay, leaving any spawns created during the delay alive and well, minus the last one.

I know it’s something simple but any help would be appreciated.

The simplest way would probably be to add the destroy logic to the spawned blueprint. So, On Begin Play, Delay 5, Destroy Self. One downside is that it may not be the most efficient way depending on how many are being spawned.

you need learn to use arrays, you can store all spawned objets.

actually the better option is to use the Set life span. Basically takes an actor and sets it’s life span. When the time ends the actor is destroyed. Much cleaner and doesn’t add over head with array and looping through it to destroy the actors.
Thanks for the ideas though, helped me test / try things which let me stumble upon the set life spawn option. :slight_smile:

1 Like

this solution is a little “Laugh now, cry later.”, them you over head each frame by each spawned actor. But if you are made a game for pc and spawn few actors probably you don’t cry later.

yeap have to make sure the player doesn’t create a billion of them, but it’s not too bad / much of a load, adding upwards of 200 of them, running a fire explosion effect. In my game the players resource will prevent but a limited amount being spawned, so this works really well, also don’t have to allocate multiple arrays for the AI that are creating similar, can reuse the code block as well, etc so works well. There was some problems with the array and adding, to the end properly as the array either grows too large as others delete off, or i keep refilling the allocation. Also problem is if the player spawns 200 of them then there is an array of 200 sitting around, that I then have to destroy as well to free up the memory footprint from the array itself.

You trollin’ your fellow programmers?

Ask a question, then come up with the best answer.
Well-played.

9 years must be the new Necro record…

1 Like

Might just be.

On topic though, in general wouldn’t setting “LifeSpan” be the better way to handle the issue?

My personal way would be to obj pool the actor and simulate a life span that returns it to pool.

1 Like

Followed closely by a Delay + Destroy combo inside the spawned actor in case one needed to avoid the inevitable fate of LifeSpan.

… Checking “Is Pending Kill” etc as well.

I can’t help myself. I have a question, I look it up.