• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Oct 01, 2020 at 01:11 AM by Odinwastaken for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Odinwastaken · Sep 29, 2020 at 01:50 PM · physics2dlagperformance optimizationcpu usage

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 alt text

capture.jpg (53.1 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
0
Best Answer

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);
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Odinwastaken · Sep 29, 2020 at 11:15 PM 0
Share

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

alt text

capture1.jpg (55.8 kB)
avatar image rh_galaxy Odinwastaken · Sep 29, 2020 at 11:55 PM 0
Share

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...

avatar image Odinwastaken rh_galaxy · Sep 30, 2020 at 03:23 AM 0
Share

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 alt text

capture.jpg (27.3 kB)
Show more comments

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

143 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What is most resource intensive, 2D Raycasting or physics2D.overlapArea? 1 Answer

How many Kinematic rigidbodies(2D) can i have in a device game without any lag ? 0 Answers

What factors cause a laggy networking? 0 Answers

Reduce Physics2D Lag 0 Answers

Just One of my scene is so laggy 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges