How to cycle trough enormous amount of entities (DOTS)
Hello here, I have a script that generates entities around the player and then destroyes them if they are far away. More behaviours are on the way, but I cant use normal Entities.ForEach since i am working with several hundred thousands entities and that is per player and i am cycling trough them each frame!
As you could easily guess, using foreach... caused... certain effects that could be described as bellow freezing temperatures. So foreach is definitely off the list. I can lower the amount of entities, but its still too much.
So I am asking what should I use to cycle trought all these entities without freezing the device. Any other methods of increasing performance would also be appreciated. Many thanks :)
Answer by andrew-lukasik · Nov 10, 2020 at 09:41 AM
Short answer: don't.
Keep in mind that the essence of data oriented design is solving performace problems with clever data structure not clever algorithms.
In practice this means reasoning about you current task until you realize that you don't have to iterate over 5e5 entities at all. And this can be figured out in context of your specific task only.
I thought so. Any ideas/tips worth sharing? I thought about chunks (part of dots, not my chunks) but my research in that part of dots is close to zero. I´ll look, search and learn. Thanks :)
One option, when dealing with A LOT of entities, is to cluster them into separate worlds. It will square complexity of your program (entities exist into separate, well, worlds), which can be bad, but also will reduce cluster destruction to just world.Dispose()
or destroying/moving elsewhere an array of Entity$$anonymous$$anager.GetAllEntities()
$$anonymous$$ake sure all the iterations are multi-threaded so retire ComponentSystem
for SystemBase
everywhere.
If your NativeList.Lenght
>100k and you're calling Contains()
on it >100k times - replace it with NativeHashSet
Thanks, ill look more into these concepts. One thing i realised is that instead of every tile (smallest part of the world) being an entity, I can make the chunk an actual entity that will keep all the data of the tiles/update them. If i would have chunk of 20x20 entities, that is already decrease of 400 times less entities. I have no idea how I didnt see any problem with per-frame iteration of 640 000 entities xD
Your answer
Follow this Question
Related Questions
GameView.GetMainGameViewTargetSize() problem 0 Answers
Profiler knurl ... 0 Answers
any physical/practical limit to number of lights in view? 0 Answers
Different pc performance problem 0 Answers
Low performance on Mobile build of 2D Platformer game. 1 Answer