- Home /
Why the frame of game is so slowly???
Hello, Everyone! I developed a game with unity. And it has a lot of sources included. Now the game cost 60-70ms every frame. I do not know why. Please help me to find the reason why my game runs so slowly and shaking. I have a screenshot of Profiler window. Thanks indeed. Have a nice day!
Answer by Commoble · Mar 20, 2017 at 04:38 PM
Your profiler screenshot says a big chunk of that time is being taken up by FindObjectsOfType. This is a sort of last-resort function to be used when there's no other alternative; the documentation on FindObjectsOfType says that it is very slow. You should rework your project to avoid using it whenever possible, especially inside Update or FixedUpdate.
You can read about some much more efficient alternatives to getting object references here and here.
Answer by Tasarran · Mar 20, 2017 at 05:29 PM
What is in your Update functions will run fully every frame.
Change your code so that it isn't always doing FindObjectsOfType, Find them once and store them rather than running the expensive Find function multiple times each frame.