Unity 2d static variables versus GameObject.Find("")

Evening, gentleman.

I got a number of gameobjects that do stuff. Each got a script that calculates some variables, that i need to use in other scripts. Like, controlling my player with a joystick.
Im calculating the control variable in the joystick script. Than i parse the script with GameObject.Find(“”) from the script on the player, looking for this variable and use it.

As i go, my project ends up using alot of Find functions and referencing lots of scripts and gameobjects. It appears to be that GameObject.Find(“”) needs to be put in update(), so i guess the system is searching the memory for all this number of gameobject each frame. I suppose that these searches take monstrous amounts of computing time.

So, the question is how to arrange everything the most optimal way?
Does the GameObject.Find(“”) uses much more operations?
Is using simple static variables better?
Or is it even better to create 1 super-master script with everything inside it, so there will be no need for statics, or any kinds of searches and referencing at all?

Thnx 2 all =)

Do not use GameObject.Find(). This is probably the worst and slowest way you could reference your other objects.

Do not make 1 super-master script. This will make your code unorganized, prone to errors, and almost impossible to work with. Each script should only do one basic thing. For example, your PlayerMovement script should handle player movement and only that.

The easiest way to reference other components/objects is to make a public variable in your script and assign the reference in the inspector. If you need to find objects during runtime, GetComponent() and similar functions may be helpful. But more importantly, you should cache your reference instead of finding it every frame on Update().

For example, if I have a Dog object that is supposed to follow a Cat object, I will declare the Cat object inside the Dog class, and initialize it in Start() or Awake(), like so:

    public class Dog {
    
        public Cat cat;

        void Start()
        {
        	cat = FindCat();
        }

        Cat FindCat()
     	{
     		//finds the cat
     	}
        
        void Update()
        {
        	Follow(cat); //note that we are not finding the cat in update, rather we are using our already initialized cat variable
        }

    }

This becomes even easier if we assign the reference via the inspector because then we don’t need the FindCat() function.

Woked =)

Using
Cat = GameObject.Find(“Cat”);
in void start()