- Home /
The question is answered, right answer was accepted
How To Reduce Physics Lag?
So at the moment when I run my game I get around 110% cpu power after around 30 seconds of my game being ran. Im very new to this and this is a barely made 2D game.... So I know I'm doing something VERY wrong. The game slowly increases in physics use. It was good until I started to try to add A* pathfinding to two of the enemies. I have two trigger colliders in the game as a whole. All my rigibody's are dynamic and one of the the enemies with A* has a rigibody and collider to try to give them gravity which isn't working atm. Any one got any tips and tricks to keep my game not running like a burnt potato. Thanks
Answer by rh_galaxy · Sep 29, 2020 at 03:22 PM
I would guess that you somewhere in the code keep creating objects that you forget about... If you look at the memory usage you can confirm it, also you can try this and look at the console to see if the number of objects increases with time for no reason.
Add this line to Update in a central object that you only have one of.
Debug.Log("Num obj is " + UnityEngine.Object.FindObjectsOfType<GameObject>().Length);
I used the line of code that you sent in the player object and it never went up and stayed at 35 for the whole time. I ran another test and here are the results for the physics. (For when the sleeping body become a active body is when a trigger is trigged to activate a enemy though not sure why it does it more than once because only 1 enemy has that) @rh_galaxy
Well then my guess was wrong... That was the first thing I could think of causing an increase in physics load. You will have to dig deeper in the profiler data and see if you can find what it is... It should be possible to see in more detail what is causing the CPU-load...
Ok so I did a little more digging and found that it was the enemy with A* causing all the lag. I'm not sure quite why though. $$anonymous$$ight be something to do with the path finding of it because when the player dies it stops the lag. Could also be the rigidbody. How would you suggest to fix A* or are there any good videos to watch about the subject? @rh_galaxy
Follow this Question
Related Questions
Problem with profiler spikes caused by Semaphore.WaitForSignal 0 Answers
Reduce Physics2D Lag 0 Answers
Just One of my scene is so laggy 0 Answers
Snapping System Optimized 0 Answers