Infinite loop error

I’m making a simple block building game where you can save and load different worlds.

My problem occurs when loading into a world. Usually it loads everything in fine, but after it has to load in roughly 2,000 blocks, I get the error displayed below.

Screenshot (1452)

Below is my load game set up

because it takes a lot of time.

even if you don’t get that error, i’d recommend you to spawn elements across multiple frames.

also i would recommend to use an array of a struct with classes transforms and tags instead of 3 arrays.

also collision handling “default” could be consuming a lot of time, depending what the default is and what’s set in the object. i would set it to “always spawn dont check for collisions”.

the big question is “why do you need to dynamically spawn 2K objects”? can’t you have something like world partition, data layers, level instance, sublevels, pcg, or other stuff?

also doing it on begin play is not bad, but my gut tells me there could be race conditions if you depend on that somewhere else.

1 Like

I’ve set spawn actor to always spawn, how would I go about spawning them across multiple frames?

grab that list of actors to spawn and save in a variable in the class. (toSpawn)

have a variable for how many actors to spawn per frame.

have a function that spawns actors (SpawnActors)

inside you loop the toSpawn array, from the last point until last+howManyPerFrame.

you spawn.

update last.

set a timer for next frame to the same SpawnActors functions.

if last >= total then return without setting a timer.

1 Like

this is called Lazy spawning method tho, It is highly useful in spawning large number of actors like 10-20k