A way to loop through only the GameObjects within the screen?

Is there a way in Unity to loop through only the rendered GameObjects that are displayed within the screen and are in a particular layer?

Say if there is a layer called Enemy, and there are many enemy GameObjects in the scene. The enemy GameObjects are in the layer called Enemy. For efficiency reasons, I only want to loop through the enemy GameObjects that are appearing on the screen instead of checking every single GameObject in the whole game.

Make use of the OnBecameVisible() and OnBecameInvisible() callbacks in a script that you attach only to your enemy game objects. These callbacks could change the state of a list that some manager game object owns.

If it’s only for efficiency, often what you think will work faster, won’t, or barely saves anything.

There are lots of ways to find “things I care about.” Like every enemy could, once every 0.5 seconds, check if it is within 100 meters of you, and add/remove itself to/from your personal “nearby” list. That would probably be as good as an “is visible” list.