Hi,
Is there a general guideline on how and where to use getcomponent vs findobjectoftype in getting a reference? Thank you.
Hi,
Is there a general guideline on how and where to use getcomponent vs findobjectoftype in getting a reference? Thank you.
Hi Guybrush,
FindObjectOfType returns the “first” object it finds in the entire scene, whatever Unity defines as “first.” Use this method only if you know that there is only one object of the type searched-for, or if it does not matter which object (of the type searched-for) you get.
GetComponent works the same way as FindObjectOfType. The difference is that it looks for the object on a specific game object. Use this if you know the game object.
Did this clear it up for you?
See also:
Thanks a lot, yes it did
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.