More efficient to have a simple script on many game objects or a list of game objects and cycle through it?

Hello,

Let’s imagine I have 500 wall sections and I want to track the health of each wall section.

Do you know if it is more efficient to:

1/ add a script to each wall section game object containing a health variable (and no update() part)

2/ have a list of wall class with GameObject and Health data and then use a find function to find the wall in the list when interacted with.

Would the answer remain the same if I had for example 100,000 tiles… when is a list too long.
If 100,000 and option 1 - it would be possible to deactivate large counts of the 100,000 tiles (e.g. not on screen).

I did some brief research but didn’t find anything related to this - apologies if I miss something.

Any thoughts or suggestions?

Thanks,

Unity has published a blog post about your concerns.

If you know you will have a large amount of entities, then, use a manager handling them (in a list, or in a dictionary with instanceID of the gameObjects as key and a struct containing the gameObject and the health as value for instance).

I am not familiar enough with Entity-Component-System, but it may fit your needs here.


Would it be possible to deactivate large counts of the 100,000 tiles (e.g. not on screen).

Even if a tile is off-screen, I believe enemies can still attack those tiles, can’t they?