Why does GetComponent<>() need to be in the Start method?

Why does GetComponent<>() need to be in the Start method instead of just at the top with variable declarations?

Thanks

Because it’s not just a variable, it’s referencing an object. So Unity needs to grab (get) the component from that object.

Technically, you could make a public reference or a serialized field reference to the object and then get the object yourself by dragging it into the public/serialized field in the inspector. I think that’s effectively doing the same thing as grabbing it in the Start method.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms