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

What does Default Solver Iteration Means?

Discussion in 'Physics' started by AminAghajoon, May 7, 2019.

  1. AminAghajoon

    AminAghajoon

    Joined:
    May 17, 2013
    Posts:
    20
    I'm trying to understand Unity Physics engine (PhysX), Can somebody explain that what exactly Default Solver Iterations and Default Solver Velocity Iterations are?



    This is from Unity documentation :

    Default Solver Iterations: Define how many solver processes Unity runs
    on every physics frame. Solvers are small physics engine tasks which
    determine a number of physics interactions, such as the movements of
    joints or managing contact between overlapping Rigidbody components.
    This affects the quality of the solver output and it’s advisable to
    change the property in case non-default Time.fixedDeltaTime is used,
    or the configuration is extra demanding. Typically, it’s used to
    reduce the jitter resulting from joints or contacts.​

    Please provide some example of how it works and how does increase or decreasing it affects the final result?
     
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    In mathematics, an iterative solution method is any algorithm which approximately solves a system of unknown values like [x1, x2, x3 ... xn] by repeating a set of steps (iterating). Often, the system of interest is a set of linear equations exactly like those seen in algebra class but with a prohibitively high number of unknowns.

    Starting with a guess for the solution to each unknown, which could be based on a similar, known system or could be from a common starting point like [1, 1, 1 ... 1], a procedure is carried out which gives an approximate solution which will be closer to the exact values. After only one iteration, the approximation won't be a very good one unless the initial guess was already close. But the procedure can be repeated with the first approximation as the new input, which will give a closer approximation.

    After repeating a few more times, we can expect a reliable approximation. It still isn't exact, which we could confirm by just plugging in our answers into our original system and seeing that it isn't quite right (after simplifying, we would end up with things like 10=10.001 or something to that effect). That said, if the approximation is close enough for our application, we stop iterating and use it.

    These lecture notes courtesy of a Notre Dame course give a nice example of this in action using the well-known Jacobi method. Carrying out an iteration of an iterative method outputs an approximation that is better than the input because the methods are defined in a way that causes this to happen, and this is a property called convergence. When looking at why any given method converges, things get abstract pretty quickly. I think this is outside the scope of your question, especially since I don't know what method(s) Unity uses anyway.

    When physics is calculated in Unity, we end up with a lot of systems of equations. We could draw a free-body diagram to show forces and torques during a collision for a given FixedUpdate in a Unity runtime to show this. We could try to solve them "directly", which means to use logical relationships to determine the exact results of the values (like solving for x in algebra class), but even if the systems are on the simple side, doing a lot of them will slow the execution to a crawl. Luckily, iterative, "indirect" methods can be used to get a pretty good approximation at a fraction of the computing cost.

    Increasing the number of iterations will lead to more precise approximate solutions. There is a point where increasing the number of iterations gives an increase in precision that is not at all worth the processing overhead of doing another iteration. But the number of iterations for this point depends on what you need your project to do. Sometimes a given arrangement of physics objects will result in jitter with the default settings that might be improved with more solver iterations, which is mentioned in the manual entry. There isn't a great way to determine if changing solver iteration counts will improve behavior or performance in the way that you need, except for just trial and error (use the Profiler for a more-objective indication of performance impact).

    For the record, my experience with this subject is from a control theory perspective, not from mathematics or even computer science. If my description has any inaccuracies, hopefully someone will point them out.
     
    Last edited: May 7, 2019
  3. AminAghajoon

    AminAghajoon

    Joined:
    May 17, 2013
    Posts:
    20

    Thank you for your complete answer @Hyblademin, It's exactly what I was looking for :).