Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Physics2D gets called without using it

Discussion in 'Editor & General Support' started by WhiskyJoe, Dec 16, 2013.

  1. WhiskyJoe

    WhiskyJoe

    Joined:
    Aug 21, 2012
    Posts:
    143
    Hey,

    I've been profiling our project to see if I can find some bottlenecks, or general points where I can optimize the game and at some point I noticed that Physics2D showing up in the profiler.

    I didn't really expect this to show up, because we're not using any of 2D stuff from unity. Is this intended? As in, is unity under the hood using 2D physics where it sees fit, or do I have something different going on here?
     
  2. WhiskyJoe

    WhiskyJoe

    Joined:
    Aug 21, 2012
    Posts:
    143
    Up up and on top!

    Tried searching for some option that might or might not be on, but I can't seem to find anything. Even in an empty scene (not even a camera) there seem to be calls to Physics2D.

    Also before I made this post, I searched the net, but I can't seem to find anything related to this.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There are calls to a bunch of stuff even if you don't use it (3D physics, mesh skinning, particles, etc.). I suspect it's just doing something like "if (numberOf2DObjects == 0) return;". Do you actually see any time spent in the call?

    --Eric
     
  4. WhiskyJoe

    WhiskyJoe

    Joined:
    Aug 21, 2012
    Posts:
    143
    There are 3 calls to Physics2D; Physics2D.DynamicUpdate, Physics2D.FixedUpdate and Physics2D.Interpolation.

    Only Fixedupdate is taking up some time, ranging from 0.01ms to 2.3ms depending on the scene, which I think would be kind of a lot for something that isn't used. I should also note that this number is jumping all over, so it's not really something stable.

    I can imagine it might be a check and it doesn't really do anything beneath the hood, but I wouldn't have guessed it was going to take up that much for not doing anything :)
     
  5. Iamdain

    Iamdain

    Joined:
    Feb 3, 2010
    Posts:
    90
    2015 and bump on this. Taking up 0.5-1ms on iOS test devices and adding several frames. Fifth highest CPU consuming task in profiler on the device I'm looking at now.
     
  6. Bravo_cr

    Bravo_cr

    Joined:
    Jul 19, 2012
    Posts:
    148
    2016 and bump on this.