How to respawn multiple actors?

Hi! I’m trying to create some sort of checkpoint that will hold an actor or more as a reference to respawn them via a key input. It works with one actor, but I can’t figure out how to configure it for many actors, arrays.

Checkpoint Actor

GameMode


If I run this, the engine will freeze :slight_smile:

Three things that jump out immediately:

  • you Destroy it first and then try to access it:

  • nothing is being added to the array, the wire is disconnected
  • most importantly - do not modify the content of the array while operating on it - you’re creating an infinite loop; every time we iterate, a new entry is added.

The For Each Loop node warns about this.

1 Like

Sorry, it was linked but I forgot to link it for the screenshot and with that code it will freeze the engine

You’ve got 3 issues. Must fix all 3. Especially the last one.

yes, I really don t know how, I just want it to work like for an object

Sadly, I can’t interpret it. Not sure what needs to happen.

Ok, I will be back with a video

if you plan to ‘respawn’ something just don’t destroy it.

disable it instead but setting it hidden in game and disable all collsion, then when you respawn you just reenable it

You are not removing anything from the objects array. That means the array will always grow and loops will be longer each time. Adding and removing from an array is not a simple mechanic.

Ok so, how can i do this action but with arrays?
I’m so bad at using arrays so all my attempts lead to freezing or crashing the engine…
I just want to be able to respawn any number of actors as I do with one in this exemple.


It’s unclear how it’s all suppose to work. Perhaps explain first what the goal is. How are the checkpoints and the obstacles going to work?


First of all, in 9/10 cases it makes no sense to destroy actors:

  • have them (or the checkpoint) store their original transforms on Begin Play
  • restore their transforms when resetting

Spawning is expensive, hiding / showing is virtually free by comparison. And you do not need to deal with any of the issues you’re having… Consider the following:

  • the aBoxes actor has a bunch of static meshes that simulate physics and cars can knock them over:

  • the aCheckpoint actor calls the linked aBoxes actor’s event to reset the whole thing:

The aBoxes is picked from the level, like in your example, and assigned to the aCheckpoint’s instanced editable variable.

  • the result:

Is this any close to what you’re trying to achieve?

1 Like

There will be more actors in the world who are the same! As I have for example “BP_2Boxes” and in the world I will have 10 x BP_2Boxes (BP_2Boxes_01, BP_2Boxes_02 … BP_2Boxes_10).
So I will have another actor that will be the checkpoint where the respawn code is. What I want is to respawn these 10 x BP_2Boxes when I fire the event.
And why I need to destroy the actor is to not spawn another actor and then be 20 x BP_2Boxes. I have to destroy the current 10 x BP_2Boxes to make them reappear in the world.

The checkpoint actor obtains references for each 10 x BP_2Boxes through an actor variable that is of type array. And then the code that I have problems

Imagine that you have 10 actors like the one on the left with 2 boxes and on the right is the actor who is the checkpoint and holds the respawn code and has an actor array variable that assigns all of these 10 left actors. When you press the R key, all these 10 actors will be destroyed and then spawned in the same position.

I hope I made myself understood now

No need to respawn anything. Why complicate things. If you need something disappear at some point, hide it, show it back when needed.

It seems what I posted fits well.

I don’t want to do with hide !! Is it really not possible to respawn the actors like i do with one??

Ok, I found the solution. Thanks to ChatGPT :))
Thank you all for trying to help me!

No Need to destroy the actors & re-spawn them. Just reset their transforms with the ones saved in the array and reset their physics. You will get a big performance loss is you use what Chat GPT blindly created. @Everynone had the correct idea.

1 Like

Ok, I will do some tests with your solution and come back