Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: Disastercake on July 13, 2012, 03:14:33 PM
-
I want to try to avoid GetComponent as much as possible in my code. What is the best way to grab something like a UILabel component to change it's text when it's created at runtime?
-
Create a local (private) variable of the type of the Component and only GetComponent<type> once for Awake() or Start(). From that point on you may reference the variable rather than having to look up the Component all the time.
I'm unsure whether GetComponent has a performance hit like Find does.
-
GetComponent isn't very expensive, but it's still better to cache the result.