So I saw something very much like

A few things first. If its performant then it’s ok, sure. I don’t have the Unity source code so I can only infer things from what they have talked about.

Lets psuedo what this is probably trying to do


Now lets create the psuedo for what is actually happening

That’s pretty expensive and not what we actually wanted.

Lets talk the quick n dirty way to make this a bit more like what the original pseudo intended. The original code indicates that there is only 1 player and we want access to it somewhere else. Sounds a lot like the exact conditions for a singleton. For a MonoBehaviour we can do this in a number of ways. We’ll discuss more robust solutions another time. So the least robust but quickest is.

In the Player.cs


and then the orig code becomes




If somebool is a property and not a field or has knock on effects, we perhaps even go further and look at using the OnBecameVisible, OnBecameInvisible messages.