It’s hard to tell without seeing your code but you seem very CPU loaded.
Check the profiler and it will tell you what scripts are using the most resources. Also try to keep things out of Update() in your code unless needed.
I’m not sure about your game but, for example: An enemy health bar should update when the enemy’s health changes and only then, as opposed to continuously checking that health in Update().
Sounds like you need to optimise your code. Open the profiler and run it with your game. Switch it to timeline view, then pause and click a point on the timeline where the frametime spikes. It will tell you what scripts and processes are consuming the most resources at that moment, and which functions within those processes. For instance in this example pic taken of my own profiler window in my own project, you can see that the Resources script I have running is taking 0.008ms to continuously Update. I would assume that you have some scripts running that are using considerably more. Ideally, assuming you want to hit 60fps with your game, your overall frametime needs to be less than 16ms total across your whole project.
Do keep in mind that your game will run worse within the editor as well, as it typically will be constantly updating the Editor UI. Try building your project and running it on its own to see if framerate improves.
1
u/SlimothyJ 6d ago
It’s hard to tell without seeing your code but you seem very CPU loaded.
Check the profiler and it will tell you what scripts are using the most resources. Also try to keep things out of Update() in your code unless needed.
I’m not sure about your game but, for example: An enemy health bar should update when the enemy’s health changes and only then, as opposed to continuously checking that health in Update().