- Home /
Question by
b2hinkle · Jul 18, 2018 at 11:08 PM ·
c#optimizationgetcomponentslowenabled
does using get component slow down game a lot?
i have a lot of get component lines in a part of my game. Is this inefficient?
capture.png
(28.7 kB)
Comment
Best Answer
Answer by Cynikal · Jul 18, 2018 at 11:40 PM
GetComponent is indeed a slower process, but it depends on how you're using it.
Are you literally calling it in the Update every single frame? If so, you should cache it.
Sometimes, you can't actually get away from using it, but you can limit it.
That portion of code looks fine the way it is. However, it also depends on where it's located.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
C# GetComponent, component not turning off. 2 Answers
Disabling scripts 1 Answer
Enable script on parent 2 Answers
Multiple Cars not working 1 Answer