Recreate in 1 single frame

Hi,

i have the current problem that Destroy happens at the end of the frame and DestroyImmediate is strongly discouraged to use. so how to go about recreation in 1 frame?

There are Ships , those Ships have shipparts and those have blocks.

The shipparts have a Data Array behind them with the important info like hp of blocks etc.

The Funktion Shippart.UpdateShippart() is supposed to kill everything it has, read its data and create a block for every block in its Data Array.

What i tried / what can not be used:
A bool in the Update funktion (because this would lead to every shippart having an update funktion)

IM not sure exactly what you need but everything in update in every script will be executed each frame so you should be no problem to destroy and instantiate in one frame. Try a for loop to scan the array and destroy/create each block instead of a bool in the update.

here are loop examples

foreach(Data d int dataArray)
    {
        Destroy(do);
        //or whatever
    }
    for(int i = 0; i < dataArray.Length; i++)
    {
        //do whatever you need to do with dataArrray[i]
    }

Sorry i was not more specific, i mean more like this:

public void recreator(){
int c = 0;
foreach(Data d int dataArray)
    {
        c++;
        Destroy(do);
        //or whatever
    }
    for(int i = 0; i < c; i++)
    {
        instantiate(someObj);
    }
}

In a single frame run.

Garbage collection is not going to like this at all (avoid destroying objects as much as you can, reuse them if possible), but Update() is the place to do it. Have 1 object controller gameobject that is the only one having the script. Then something like:

void Update() {
  ... Destroy objects here...

  ... Instantiate objects here...
}

This should make them appear for 1 frame duration.

Also should mention that this will most likely make your game very slow, compared to how it could perform.