Search Unity

Possible reasons for different friction behavior in Editor vs Build?

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

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    I don't expect Unity Physics to be deterministic, and that's fine. But I have one specific case where something is behaving completely differently depending on whether I'm running in the editor vs running in a build. In both cases this is running on the same computer. I'm just trying to understand whether there's anything I can do to better ensure that the behavior in the built version acts more like it does in the editor (otherwise it's pretty hard to design things if they're going to run very different in a build.)

    The specific example is this: I have a block (Just a cube with a rigidbody) being pushed by a moving platform horizontally across the ground. It looks like this:
    upload_2019-5-7_11-42-39.png

    In the editor, when the platform pushes the block, the block slides along the ground. However, in a build, the block slides a little, then gets flipped over, and kind of rolls along. Every couple of meters it flips over again. It doesn't roll like a ball: It just flips over once and then slides again, then it flips over again a second or two later, and will keep doing this as long as it's pushed.

    The platform is a kinematic rigidbody, being moved via MovePosition every FixedUpdate. The block is a non-kinematic rigidbody with a physic material on it. When it runs it the editor, I have never seen the block flip over. When I run in a build, it always flips over. The behaviors are very different.

    Does anyone have any suggestions as to what would cause the difference in behavior between the editor and a build, and whether I can do something to make them more similar?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,770
    Some video, demo, gif could be helpful.
    Also, which Unity version you are running?
     
  3. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    I'd follow these steps for debugging the problem:

    1. Show the physics properties of the cube, the ground and the platform on the screen. Include the properties of the rigidbodies (mass, inertia tensor, inertia tensor rotation) and the properties of the physics materials assigned to all the colliders involved.

    This will expose any physics difference between the Editor and the build.

    2. If there are no differences then try modifying the physics settings in the Editor until you could reproduce the same behavior. The main setting I can think of is the Friction Model, but try all other settings that have effect in contacts and friction.

    If you could reproduce the issue within the Editor then you could find out why the settings are changing in the build. Maybe some editor-only code is bypassed in the build, or there's some bug that doesn't initialize the physics settings as they should.