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.
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.
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:
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.
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.