- Home /
Physics2D.DestroyShapes is constantly called. What does it do though?
I made a game which has some performance issues, so I used Profiler to find out why it does. So after testing for a while now, I know that Im doing something fundamentally wrong. The thing that causes the game to lag, with enemies or just with bullets flying around (description of them at the end). The thing that causes these lags is "Physics.DestroyShapes". Even if there are only 20 bullets in the level this will cause the game to drop below 60fps. And yes there are only the 20 bullets in the room nothing else... And the fps drops to 30 or 20. The bullets and the profiler when 20 of the bullets are in the level are shown in the pictures.
Thanks for your help and time
2017.3.0b3 Its the beta version of the new Unity.
Answer by Blue-Mirror · Nov 29, 2017 at 07:31 PM
This helped me :) https://answers.unity.com/questions/1115477/why-is-there-a-physics2dsimulate-spike-with-severa.html
Moving the bullets per Code wasnt the problem, it was that I didnt move it via the rigidbody.transform.position = xxx. I moved it with transform.position = xxx instead, which causes the colliders to be recalculated everytime.
Answer by Bunderant · Jan 19, 2018 at 10:32 PM
I was having the same problem, but moving via the rigidbody wasn't a great option for me, and caused some issues with my custom collision handling.
In my project, the Physics2D.DestroyShapes accumulation disappeared once I went back into the Physics2D project settings, and made sure the "Auto Simulation" property was checked on. I had it unchecked before, since I was handling everything I needed myself.
Dunno if that's a bug in Unity, exactly, but I'll probably get a repro project going and submit a report anyway.
Answer by AlterHaudegen · Dec 29, 2020 at 11:38 PM
In case anybody runs into this years later and had to bang their head against this issue for hours like I just did: It looks like all physics 2d shapes are destroyed for colliders that don't have a rigidbody attached to them. Simply attaching a kinetic Rigidbody2D completely made the problem go away for me.
Your answer
Follow this Question
Related Questions
Physics2D friction not working 2 Answers
Photon position syncing 0 Answers
After Collision Matrix change in runtime, effects not immediatly visible 1 Answer
Physics2D.BoxCastAll() imprecision? 0 Answers