Spawning big amount of actors cause long loading time.

I’m using a recursive function to spawn a somewhat big amount of actors.
As the result of recursive run around 50 actors are spawning one after another and that cause 0.5-ish hanging time.
25 actors are spawning without noticeable to a human eye lag though.

Is there any way to lower spawn time? Actors are very basic. They represent a flat tile with 50% transparent material and that’s it. They are actually 3D with minimal Z scale so they seem flat. Is there any solution like making tile actually 2D so it’s rendering goes much easier?
Spawning happens through a gameplay so lag is critical for a final product.

Is it just visually / right next to each other?

Then decals might come in handy combined with one or two blocking volumes to have collision.

Otherwise would it be acceptable to do it not exactly at the same time? You could add a “spawned tiles per second” number. Divide it by “Delta Seconds” from “Event Tick” / “World Delta Seconds”, round up, pass that number to your recursive function / make a for loop out of it and just run it that often. Then the next frame You go on until the condition for your recursive function is met?

Like this you stretch it out and reduce the impact on FPS / game flow for the trade off that they don’t spawn at the exact same time but over this time of half a second or whatever.

Thanks for giving interesting ideas, Erasio.

I also had an idea to stretch spawn of actors, but delays at functions are forbidden unfortunately. I’ll definitely try a for loop to make function hang in the air a little.

Decals are also cool to consider, right now I’m spawning tile actors which collides with each other, so I’ll try to replace them with decals.

I’ll try both ideas and be right back.

I’ve deleted static mesh and drawn similar decal, but no performance improvements are noticed unfortunately.
As for delay - I didn’t completely understand your idea. What I did just now is just increment delta time until it’s 0.1 second, but this also makes recursive spawn call lag. Could you explain delay thing some more please?

Basically instead of one recursive function you find out the number of meshes you can spawn per second without serious impact on your game.

You save that value (or just hardcode it) and create a for loop which runs for that amount divided by “World Delta Seconds” which will provide you with the appropraite amount of actors you should spawn since the last frame. Round up that number (so it’s impossible to not spawn anything) and plug that into your for loop. In front of your loop / function / event you have a bool which checks if you’re currently inside of the “recursive” function. If you are then you run that for loop. Inside of it there’s the spawn and the condition for your current recursive function. If that condition is met you set your bool to false and break out of the for loop.

The branch (whether or not you are in that function and it should run the for loop) should be called each tick (frame). Ideally you have a spawner where you can turn off tick when you don’t use this to save a bit of performance. There’s a lot that could be optimized about this approach. First and formost moving away from BP which is why I don’t consider that too much in this explenation.

Hope this helps.

Cheers

Hey, Erasio. Since our last talk I’ve translated all my tile generation related stuff(recursion function and actor spawning) to a C++.
That’s fantastic how drastically different it flows. It works just right and smooth without any distribution of spawning by frames.
I’m sure rest of your advice would work as well, so I’m marking your answer as correct.