Generate many actors in visual field

it is not a very UE4 question…But about how to program.
I am working on 2D sandbox game,dealing with visual field tiles.Like Terraria or minecraft,It’s a huge world,so we maynot generate the whole world in a time,but generate those visible part.
Yet Still there are many many tiles in visual field.about 5 to 10 thousands depend on how large player can see.
And when player move,for example move to right over a certain distance,new tiles shall be generated.At this moment,It will be one thousand tile need to be generated.



Maybe these pictures will make it more clearly.
I have make a limit ,just generate 100 or 200 actors in one frame.It works~
But if player move very fast,question still appear,generation just can’t catch up.

So I was wondering ,Will it be better not generate thousands of actors at one time,everyone with a sprite component,But generate four or five actors,every one with hundreds of sprite component?
And be sincerely,how did Terraria deal with this problem?Let the computer run smoothly nearly ten years ago.
Ay…
Will be very appreciate for any answerThank you

Look up Octree.

Also you just implement a multi-threading system and you will never have a situation where you have anything that needs to catch up unless the CPU in use is just that bad.
While the first 200 are generating, you can also be generating the next 3 or 4 sets of 200.

Some things just aren’t built to handle billions of actors (VB forms for instance). But Unreal actually can if you do it properly. HISM, or removing the old ones from screen by using a pool, and manual instancing.

1 Like

Thanks~
I just went to learn about the octree~and some other trees,like k-d tree and HISM.They are very good algorithm for sorting data and render 3D vegetation.But seems not very good for 2D games?Tiles are always clustered fairly close together.Haven’t try ,just Guess according to mathematical logic.
And multi-threading system seems to be very helpful,don’t need to worry about stucking.I will try to use it now~
Thanks again~

In 2d instead of octree you have Quadtree.
Same concept.
It allows for faster sorting/generation.

Coupled with the other techniques it should make generation of a 2d level at runtime a breeze.

Thanks~
I did a little research and some experiment of octree and multi-threading system yesterday.
FRunable,FNonAbandonableTask,and TashGraph.All these threads shouldnot create or modify any actor.Can only do it in GameThread.So ,they are good,but not suit for this situation…
And Octree or Quatree,they are more good at store discrete point data,sandbox world have too many tiles gather together,and I need their x,y coordinate to modify and create different terrain,mountain,cave,forest etc.Quatree is a better way to sort and store data,but a little complex to modify on the whole.(maybe)

And one of my friend told me there is something call Composite Collider 2D,it’s U3d’s …component/tool.whatever.It build vertex and mesh to combine many tiles into one block.Like I did guess ,but much more advanced.It’s also used by TR and MC.And it can certainly be achieved with UE4.
So I am fighting with it now.

But still very grateful for your help,you lead me to know all these advanced ways to programming~

To get to the game thread, you normally have your multi threaded task handle a pool or buffer, set everything up, than hand off the buffer to the game thread for spawning.
It’s complicated because unreal only spwans things on the game thread, so I’d you do too many items at once you risk degrading performance.

You should still be able to pre-calculate things so that the creation is faster though.
The simpler the loop to add instances, the faster it will solve.

Also, I’d you think about it, you really only need to achieve a 2 tile x vertical number of tiles on screen per frame in order to prevent most issues…