Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug positional / sync issues when disabling / enabling / moving Rigidbody instances in Unity 2022LTS

Discussion in 'Physics' started by darbotron, Sep 4, 2023.

  1. darbotron


    Aug 9, 2010

    Have recently upgraded to 2022LTS (2022.3.4f1) from 2021LTS & am definitely seeing some super weird

    / Gfx transform behaviour since upgrading.

    I maintain a game agnostic Unity framework & the super basic space-invaders-alike sample project I have (which has worked fine since Unity 2017LTS) had (I fixed it) some super strange behaviour with pooled


    Specifically when cycling pooled objects:
    1. acquire projectile from pool & enable, move projectile to launch position & set velocity
    2. update projectile til end of lifetime (collision or timeout) then put projectile back into pool, zero velocity, & disable
    3. goto 1
    When re-enabling a previously disabled projectile it intermittently either:
    • appears in the position it was in when disabled & continues from there
    • appears in the position it was in when disabled for a single frame, then appears in the correct place & continues from there
    NOTE - the pooling code in the sample has worked fine since I first wrote it in 2017 LTS

    I have got a workaround / fix though...

    The problem seems to be some sort of transform sync issue between

    If I use only
    • either
    • or
    To set the pooled object positions after enabling them then I get the issues above.

    However, if I use both
    to set the object's position after I enable it I don't get any problems.

    • I also experimented with making the pooled rigidbody kinematic and disabling their colliders whilst inactive and that didn't seem to make any difference
    • I also thought this might be related to this forum post but deleting DynamicsManager.asset & re-creating it made no difference to the issue
    • also I noticed that the 'Auto Sync Transforms' check box wasn't ticked in ProjectSettings -> Physics but checking / unchecking this doesn't seem to affect the issue either.
  2. darbotron


    Aug 9, 2010
    have made a minimal repro project & submitted a bug to Unity - here's the same thing in case it helps anyone else

    • load 'samplescene.unity'

    • press play

        • projectiles are spawned from a pool every 0.5s

        • they move upward until they hit a trigger at the top of the screen, at which point they are returned to the pool

        • there are 4 projectiles in the pool

        • projectiles are rigidbodies and move with a set velocity
    • note that the visual representation of the projectiles flickers when they are disabled / enabled (unsure what happens with the colliders etc.)
    In Projectile.cs there are two commented scopes with the same comment:

    // object position sync breaks if either of these two lines is commented
    //projectile.transform.position = startPosition;
    projectile.m_rigidbody.MovePosition( startPosition );

    if only one of [projectile.transform] or [projectile.m_rigidbody.MovePosition()] are used the issue occurs.
    if BOTH are used then the issue goes away.


    Attached Files:

  3. jonjoh1


    Oct 2, 2023
    I think I'm having the same issue in our project. But it seems inconsistent when it happens. It seems to be happening consistently when the frame rate is low, I think. Haven't been able to verify it for sure. There are also some differences between editor and build, but that could also be frame rate related. This happens only after an upgrade from 2021.2.12 to 2023.3.10.

    When teleporting the player vehicle by using transform.position, it get set back to the previous position the next physics update, so teleporting it that way doesn't work at all. Actually, it seems to happen to most if not all rigidbodies. Setting the RB.position as well as the transform.position removes the issue. Calling Physics.SyncTransforms after setting the transform.position also removes the issue.

    Our ragdolls are experiencing what I think is a related issue: when they are switched from animator control to ragdoll (kinematic is turned off on all RBs), the rigidbodies (and so, all the bones of the ragdoll) are instantly teleported to some random positions far away, so the ragdoll essentially explodes.

    It's as if the physics engine skips the step of copying the modified transform position into the rigidbody before simulation.

    The 'Auto Sync Transforms' setting makes no difference as expected. Nothing else has changed in the project except the Unity version.

    @darbotron Do you have a link to the issue tracker so I can follow it?