Search Unity

Physics performance?

Discussion in 'Editor & General Support' started by Foxxis, Dec 3, 2007.

  1. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Hi all!

    I have a game where at any one time there can exist 10-20 objects fully controlled by physics. They have force and torque added to them every physics frame (as they are subject to global forces defined through scripting).

    I have noticed that my performance decreases linearly with each added object. As far as I have been able to determine, it is not due to graphics or non physics related code (I have run the game without rendering the objects, and inserted metering code to check that my code runs efficiently).

    My only remaining hunch is that it's the physics engine eating away on the fps.

    My questions:
    - Am I doing a "no-no" by constantly inserting forces?
    - Are there any recommended tools that can help me further locate the performance issue?

    Many thanks in advance!
     
  2. Martin-Schultz

    Martin-Schultz

    Joined:
    Jan 10, 2006
    Posts:
    1,377
    Not that I can answer your question, but I'd like to hear what your hardware specs are you were running it on. I did some testing over the weekend with approxiamtely 150 physic'ed spheres falling down at once, bouncing and hitting each other without any noticeable performance hit, but I need to state that my hardware was a 2.4 GHz Macbook Pro, so not a "weak" machine. Interesting question you raised anyway. Can't await the answer to it!
     
  3. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Macbook Pro, so it's not a weak machine. Also, my case is not similar to the one you tested, as I continually set forces instead of just letting the physics engine run based on an initial situation.

    I have been able to improve performance by using a ConstantForce instead of resetting the forces each frame, so I am fairly certain that there is some overhead in the physics engine when setting Force/Torque. I'd love to hear some official elaboration though.... :)
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    It could simply be script-processing overhead. Anything being run in FixedUpdate gets executed 50 times per second per object, and those can add up fast. ConstantForce is certainly a more efficient option.
     
  5. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Indeed. I have adressed this and now limit what's done during fixedupdate. I have also increased fixedDeltaTime since I don't really need a high physics precision. The next step will be to move much of the decision code to Update instead of FixedUpdate and try to optimize things further.

    Thanks for the reply - any other tips would be most welcome! :)