FindObjectOfType() .vs public instance

Background: I have two objects let’s call them, A and B, and A is a prefab which instantiates in run time, and B is a prefab too but it exist in every scene from the start. (this information probably won’t make a difference in the answer, but I want to be thorough).

Question I want to access B from A, I could make a public instance of B and access it from A, or I could use FindObjectOfType() method in A, to find B. Which one is better, and more professional for the long run?

Thank you in advance!

FindObjectOfType() is quite heavy, it will go through every gameobject in the scene until it finds the one you’re looking for, and thats basically the same for any Unity Find method. As to using a public reference is straightfoward to the object.

If you are curious about how Unity operates and how to avoid performance issues, read this article from LearnUnity: Fixing Performance Problems - Unity Learn, its quite extensive, but worth the time. There you can also find the information i just gave you.