Search Issue Tracker

By Design

Votes

0

Found in

2022.3.55f1

6000.0.32f1

6000.1.0a9

Issue ID

UUM-91101

Regression

Yes

Setting the initial position of an instantiated Rigidbody behaves inconsistently when Interpolation is enabled

-

Reproduction steps:
1. Open the attached "repro_IN-90557" project
2. Open the "Assets/Scenes/SampleScene.unity" Scene
3. Enter the Play Mode
4. Spam the 'J' key
5. Observe the position that each block is spawned at

Expected result: All blocks are spawned on the left
Actual result: Most blocks are spawned on the left while some blocks are spawned on the right

Reproducible with: 2022.1.0a6, 2022.3.55f1, 6000.0.32f1, 6000.1.0a9
Not reproducible with: 2021.3.47f1, 2022.1.0a5

Reproducible on: Windows 10 (22H2), Windows 11 (23H2) (reporter's environment)
Not reproducible on: No other environments tested

Notes:

* Reproducible in Player
* Changing the "Interpolate" parameter to "None" in the "Rigidbody" Component of the "Assets/Resources/Item.prefab" Prefab makes the bug disappear
* The lower the frame rate, the more likely the bug is to occur
* If you set the default rotation on the Transform, the Rigidbody will randomly use the Prefab's default rotation instead

  1. Resolution Note:

    The behavior here is being caused by how interpolation calculates a GameObject's position. The interpolation documentation (https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Rigidbody-interpolation.html) likely explains this case.

    The spawning script has an object instantiated in and then changes the transform position. However, since that position change was not made through a physics call, that change may not fall on the same frame as a physics step, resulting in that change being ignored.

    There are multiple workarounds in this case
    1. The documentation recommends following non-physics changes with a call to Physics.SyncTransforms().
    2. Putting the spawning code in a FixedUpdate() instead of an Update() function will ensure each change happens on a physics step.
    3. Instantiate the object using an overload of Instantiate() that sets its position to where you want it to be. That way there is no non-physics change to the transform's position that the interpolation ignores.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.