Search Unity

Physics.Simulate 2D performance spike issue (with profiler data)

Discussion in 'Physics' started by apatton, Jun 20, 2016.

  1. apatton

    apatton

    Joined:
    Sep 7, 2013
    Posts:
    8
    upload_2016-6-20_11-41-27.png

    Physics is clocked under 10ms for most frames, then spikes sometimes above 500ms. It's actually quite hard to reproduce, but the spikes seem to occur when the non-kinematic objects become 'trapped' within the kinematic objects, which somehow generates tens of thousands of calls to Physics2D.ContactPreSolveAcquire.

    No static colliders are being moved (all have rigidbody attached, some are kinematic), but one of the kinematic polygon colliders has to be dynamically updated every frame (no real option there).

    Any ideas?

    *Edit: I also eliminated all OnCollision handler code (the profiler data above was from afterward)
     
    Last edited: Jun 20, 2016
  2. apatton

    apatton

    Joined:
    Sep 7, 2013
    Posts:
    8
    It seems the issue was due to the non-kinematic rigidbodies being inadvertently set to continuous collision detection (oops). After setting it back to discrete, the spikes no longer occur.
     
    malcolmmaima likes this.
  3. malcolmmaima

    malcolmmaima

    Joined:
    Jan 28, 2017
    Posts:
    2
    Thank you soo much. Solved my problem after struggling for 2weeks.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,487
    Wow, you must've had had a lot of non-sleeping bodies and/or a lot of contacts to produce a 466ms simulate time. Continuous isn't *that* expensive.
     
  5. Deleted User

    Deleted User

    Guest

    Hey, my game is freezing multiple times during gameplay for a random amount of seconds, what could be the issue? My profiler says >3000 calls for physics2d.ContactPerSolveAcquire every time the freeze happens, thanks.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,487
    That's 2D physics solving lots of contacts. Check the contact count in the 2D physics area and see how many contacts you have. If it's thousands and its intermittent then you need to figure out what is causing those contacts.