Does it make a difference where you GetComponent?

I noticed he got components in 2 different parts of the script (waypoints in awake and textMesh tracing back to update. I placed them both in the awake method and it works the same. Does it matter where GetComponent is called?
image
image

Yes, it kinda does matter. If you do it in Awake, it gets it once when the object is first created. If you get it in Update, it gets it in every frame. Since it is quite an expensive thing to do, you don’t really want to do it in Update because it will affect the frame rate at which your game runs.

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

Privacy & Terms