- Home /
difference between Gameobject.findobjectoftype<...>(); and simple findobjectoftype<...>(); ?
apart from the second being quicker to write, any performance or logic difference? thank you for your help
Answer by ARKMs · May 18, 2016 at 05:59 PM
There is not one. Is the same function, just some functions by the MonoBehaviour you can write quicker.
Like Instantiate and GameObject.Instantiate, Destroy and GameObject.Destroy, StartCoroutine and gameobject.StartCoroutine, etc.
Answer by FortisVenaliter · May 18, 2016 at 06:24 PM
The difference is scope. Functionally, they are no different.
The function is actually defined not in GameObject, but rather in Object, from which GameObject is derived. You can call the explicit version "GameObject.Find..." from anywhere in your code that includes the UnityEngine namespace. However, you can only call it without the GameObject prefix (implicitly) in a class that derives from Object. Since MonoBehaviour derives from Object, and most Unity scripts are MonoBehaviours, most can make the call implicitly with no problem.
in a class that derives from Object
with derived from object you mean from a script attached to a gameobject yes?
No. In a script that declares a class derived from object, like
public class ThisClassDerivesFromObject : Object {
...
}
i see, I just learned that monobehaviour is a big class where we write the scripts thank you!
Your answer
Follow this Question
Related Questions
how to modify this code to place it inside a car and move it along the car. 0 Answers
identifying the index of a gameobject in an array 1 Answer
Leaderboard thing ? 2 Answers
Issue with animation and gravity. 1 Answer
How to make my air plane to fly straight up (its local y-axis is parallel with global y-axis)? 0 Answers