Search Unity

Massive physics2d spikes in profiler when enabling/disabling objects

Discussion in 'Physics' started by unity_Scbce4JGiuAPkg, Sep 7, 2018.

  1. unity_Scbce4JGiuAPkg

    unity_Scbce4JGiuAPkg

    Joined:
    Sep 7, 2018
    Posts:
    1
    In our game we have several scenes we enable and disable as the player moves around so we don't have too much loaded at any one time. Currently we have a huge spike and freeze when the game disables a segment by disabling it's root object. The problem seems to a few hundred calls of Physics2d.DestroyShapes

    upload_2018-9-7_15-22-21.png

    Is there a way to stop this? We will want all the physics objects later so is it possible to stop the shapes from being destroyed? Or is it possible to spread out the shapes getting destroyed so it happens over several fames instead of causing the single massive jump?

    Thanks
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    If you destroy or deactivate a GameObject with physics components then they'll always destroy the underlying physics objects. I don't see any absolute times for the 132 calls to "Physics2D.DestroyShapes" (which isn't many calls) although each call might be destroying a lot of shapes (I have no way to tell from the image). PolygonCollider2D can produce an unlimited number of shapes each. TilemapCollider2D can potentially do the same producing thousands of shapes.

    If you could provide more detail on the times being taken here and the number of shapes involved. All that info should be available in the profiler.