- Home /
FindObjectOfType or FindWithTag
I have a GameObject which I keep between all scenes (what I believe is referred to as a singleton), and grab a reference to it using FindObjectOfType
in Awake.
But the Unity Script Reference says that function is "very slow", so I'm just wondering if FindWithTag and then a GetComponent on the script would save a considerable amount of processing time?
Answer by Eric5h5 · Apr 02, 2013 at 09:45 PM
"Slow" is relative. We're talking about computers, where "slow" could mean doing something "only" 10,000 times per second instead of 10 million times. If you're just doing it in Awake, it doesn't matter even a little bit.
As stated, it should be used in Awake or Start. You may use it in Update, which is called every frame, but will be a huge performance cost. It is always best to use that method to cache your objects once so you can then reference back to them at anytime during the program.
Yep. I only ever use Finds in Awake or Start, and I usually try to use editor references where possible.
Your answer
Follow this Question
Related Questions
DontDestroyOnLoad & Singleton 2 Answers
singleton, global vars and dontdestroyonload 2 Answers
dontdestroyonload breaks findobjectoftype 0 Answers