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 :slight_smile:

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.