Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

how to turn off physics?

Discussion in 'Scripting' started by imnieves, Feb 25, 2010.

Thread Status:
Not open for further replies.
  1. imnieves

    imnieves

    Joined:
    Feb 18, 2010
    Posts:
    13
    Hi!

    I am having trouble turning off physics. My iPhone app doesn't use it, and I notice (through Unity Pro Instrumentation) that periodically the Physics.Simulate() method is being called... this is costing me 5%-10% CPU for that moment in time... even with a completely empty scene... :\

    Does anyone know how to turn off the physics engine? (even in a completely empty scene, except for the main camera)

    Sincerely,
    Ian
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I don't think you can, but you can set the physics timestep to something like 1 so it only runs once per second.

    --Eric
     
  3. imnieves

    imnieves

    Joined:
    Feb 18, 2010
    Posts:
    13
    wow... this sounds weak.

    i was able to set it to 10 seconds in Unity Pro and Unity iPhone..., but thats not a solution, thats just delaying the inevitable... and its not clear that delaying the physics simulation might even make the impact worse (though not likely) In my profiling, the physics engine causes a CPU spike and makes the frame rate unstable if you are already maxing out CPU.

    this is actually a significant impact, moreso than even garbage collection. at leaset with garbage collection you can really minimize the effects by minimizing unnecessary/redundant calls to new.

    hmmm.....

    right now im going with the 10 second solution...

    PS... i have tried
    1) scene with nothing in it except a camera
    2) many objects with mesh colliders (set to be used as a tag only)
    3) many objects with mesh colliders (set to be used as a tag only) and a rigidbody set to not use gravity and to only be kinematic
    4) setting physics gravity to 0 (acceleration in the Y axis)

    Can someone from unity chime in on this? Its a pretty reasonable concern i think, expecially on the iPhone.

    -i
     
  4. imnieves

    imnieves

    Joined:
    Feb 18, 2010
    Posts:
    13
    To take a step back... i would be OK with setting the timestep to 1 or 10 or whatever, if the impact was minimal.. However, even with nothing in the scene, the CPU still spikes! That makes almost no sense to me. I can understand perhaps some initial spike at load time... but to continue to spike... what on earth could the physics engine be doing if theres nothing in the scene?

    Wow... i just ran a new test.. this time.. not only a new scene, but a totally new project, to be sure there is nothing crossing over from my other scenes (which have things in them)

    I am now seeing spikes as high as 33%, on a 2.5GHz Core 2 Duo... and nothing in the scene. Sounds like this thing periodically spinning.

    -i
     
  5. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    There is no switch to disable the physics completely, but the overhead should be minimal. Please contact support@unity3d.com if you are finding that the idling physics code is slowing your game unacceptably.
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    one thing that clearly helps is not using rigidbodys on anything (including not using the character controller)

    if thats the case then the physics will consume about 0 cpu time.

    A question on the 5-10%: Sure you don't missinterpret it?
    The values there are in percentage of the whole frametime.
    Yet as your scene is empty your frametime is basically 0 and 0 * 5% = 00 :)
     
  7. imnieves

    imnieves

    Joined:
    Feb 18, 2010
    Posts:
    13
    After having rebooted my machine, I am now seeing impact of Physics around .01%. This is acceptable. I am not sure what the issue could have been.

    I do have mesh colliders that are sometimes overlapping. Could that be a problem?

    Would I have to use Physics.IgnoreCollision(..) ?

    Sincerely,
    I
     
  8. Sycle

    Sycle

    Joined:
    Nov 24, 2009
    Posts:
    446
    imnieves - if you're not using physics, why do you have colliders in your scene?
     
    thebarryman likes this.
  9. imnieves

    imnieves

    Joined:
    Feb 18, 2010
    Posts:
    13
    i have colliders for raycasting... to determine where someone has touched...

    as far as i know.. to determine if you have touched something, you must make use of a collider of some kind.. i happen to be using Mesh Colliders for this.
     
    jvella_bhvr and FaberVi like this.
Thread Status:
Not open for further replies.