- Home /
What slows down my game?
Hi, This is gonna be a very general / conceptual question so please tell me if I should move this to the forum.
I want to learn how to optimize my game in terms of efficiency. The things I want to learn is:
Which is costly: Memory or computation?
Accessing a public variable of another script in Update, or storing it into a local variable and use it?
Few long functions or more short functions? Or does it not matter?
Public variables or private variables?
Where can I find answers to such questions? Thanks !
Discussion questions like this should take place in the forums.
Yes, @Dave_Carlile is right.
Unless you have a specific performance issue, then post this on the forums.
If you do post it on the forums, please close this question.
Well, for now I found my answer. If necessary, moderators can delete this question. (I'm allowing them :D )
Answer by IgorAherne · Jul 21, 2013 at 07:18 AM
Especially the line "Don't use methods which search for objects any more than is necessary. This includes methods such as GameObject.FindByTag() and GameObject.GetComponent(), as well as all the component convenience properties (transform, light, etc.). These methods are optimised to operate as quickly as possible, but they still have to search through all the relevant objects to find the one you want. The most important thing is to avoid calling search methods repeatedly in Update() or FixedUpdate(). Ins$$anonymous$$d, call the method once, store its result in a member variable of your class, and then use the member variable to access it the next time you need it." really is my answer. Plus one for this :D
Your answer
![](https://koobas.hobune.stream/wayback/20220613110527im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Particle System Optimization (.IsAlive but more efficient) 1 Answer
Are there any performance differences between a timer and using Invoke? 1 Answer
Reasonable heap alloc. per second and total ? 0 Answers
a ton of sprites vs sprite-tiling on one object 0 Answers
Efficient mesh vertex count changes? 1 Answer