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 happened to Unity 2018 in Physics? It breaks my entire game with child rigidbodies...

Discussion in 'Physics' started by Marcos-Elias, Aug 12, 2018.

  1. Marcos-Elias

    Marcos-Elias

    Joined:
    Nov 1, 2014
    Posts:
    159
    I recorded a detailed video showing how Unity 2018.2 affected my project, comparing the same features both in 2018.1b11 (where everything works) and 2018.2.1f1 (broken physics). Tested with 2018.2.2 and .3 later, same problem.



    What's happening? Kinematic rigidbodies should NOT be affected by the forces, I learned... It's impossible upgrading my project to all newer Unity versions. It worked in almost the same way with Unity 4, 5.x, 2017.x up to 2018.1b11. But final releases of 2018.x broke everything. I tried many changes, including leaving all child kinematic rigidbodies with the same interpolation settings... Nothing seems to work. Tried also Physics.autoSyncTransforms both to true and false, same bugs...

    Is that a bug or something was changed?! It's hard to believe that this critical bug still exists in a "final" release, if it is a bug...

    1 - Moving kinematic rigidbodies inside a moving non-kinematic rigidbody have a strange behaviour, they are left behind. Watch people in my bus, shown at 8:35.

    2 - Each time we put the vehicle on the ground from some height, the child kinematic rigidbodies are moved a little bit to the top on y (check at 6:19 to 7~8min). Unlike the people on a local waypoint system inside the bus, buttons don't have any script moving them, they have a collider and a rigidbody just to recognize mouse clicks.

    Both problems don't happen with Unity 2018.1 beta 11. Tested with 2018.2.3, bug still exists besides some fixes in physics.

    This bug seems related to this one, I'm not sure:
    https://issuetracker.unity3d.com/is...ild-object-to-be-misplaced-after-the-movement

    My project is too big/too complex to send a sample project, I may try exporting only a bus and some part of the map to the bug report, but I cannot do it right now.
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    If it works with 2018.1b11, but stops working with 2018.2.1f1, then it's most likely a bug and submitting a bug-report is sounds like the appropriate thing to do.
    https://unity3d.com/unity/qa/bug-reporting

    If you do not submit a bug-report, which Unity Technologies can use to reproduce the issue and test their fix against, it's rather unlikely that they're going to work on a fix, according to my experience.

     
    Deeeds likes this.
  3. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,497
    My guess is that the parent transforms are somewhat affecting the transforms in the child rigidbodies and these take the new values as an update, which should not happen. Child rigidbodies should be independent of their parents as the Rigibdody component controls the Transform.

    When you modify the RB's transform explicitly the RB takes the new values as an instant update to its position. How and when this happens is what has been worked around in recent versions (as with the introduction of Physics.autoSyncTransforms and Physics.SyncTransforms).

    I'd experiment with rigibdody hierarchies. Try to find some case where the parenthood relationship is affecting the child RB's transform in some way in one version, but differently in other. Then you could send a bug report with it.
     
    Last edited: Aug 13, 2018
    Marcos-Elias likes this.
  4. ceebeee

    ceebeee

    Joined:
    Mar 7, 2017
    Posts:
    395
    Deeeds and Marcos-Elias like this.
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,753
    Mind you still run on beta version.
    So in meantime you can send bug report.
    But you should run (revert to) stable version of Unity.
     
    Marcos-Elias likes this.
  6. Marcos-Elias

    Marcos-Elias

    Joined:
    Nov 1, 2014
    Posts:
    159
    Thanks! With this my buttons don't move anymore, nice... By the way clicking on them is still not working and passengers also continue with the problem. :(
     
    ceebeee likes this.
  7. anthonov

    anthonov

    Joined:
    Sep 24, 2015
    Posts:
    160
    Deeeds likes this.
  8. ceebeee

    ceebeee

    Joined:
    Mar 7, 2017
    Posts:
    395
  9. WallaceT_MFM

    WallaceT_MFM

    Joined:
    Sep 25, 2017
    Posts:
    394
    We've run into the same problem in 2018.2.4f1. It can be recreated in an empty project with very simple code:
    Code (CSharp):
    1. public Transform m_child;
    2. void Update ()
    3. {
    4.     m_child.eulerAngles = new Vector3(0, m_child.eulerAngles.y, 0);
    5.     // Using the line below instead will work
    6.     //transform.eulerAngles = new Vector3(0, transform.eulerAngles.y + 45 * Time.deltaTime, 0);
    7.     GetComponent<Rigidbody>().rotation *= Quaternion.Euler(0, 45 * Time.deltaTime, 0);
    8. }
    I just filed a bug report, waiting for the confirmation email. Will post a link when I get one.

    EDIT: https://fogbugz.unity3d.com/default.asp?1072709_b7putgbtoi1ia13n

    EDIT2: Unity might have fixed this in a future version, according to this issue tracker:
    https://issuetracker.unity3d.com/is...on-physics-when-parented-with-a-moving-object
     
    Last edited: Aug 21, 2018
    ceebeee likes this.
  10. Marcos-Elias

    Marcos-Elias

    Joined:
    Nov 1, 2014
    Posts:
    159
    A temporary workaround that I've found:

    NOT PARENTING the child objects at all.

    I created a new empty game object without any collider or rigidbody at the same vehicle position and rotation, then I parented all people and clickable buttons to this new game object instead. On my vehicle's Update() function I sync the position of the new object, just like:

    mycontainer.position = transform.position;
    mycontainer.rotation = transform.rotation;

    Where mycontainer is a reference to the new empty transform.

    This is not the perfect solution since it worked parented to the vehicle before, but it works for now until the fix comes. On my articulated bus I had more work since there were two rigidbodies for the vehicle, but the same idea worked too.

    This kind of bug is very very bad in a "stable" release of Unity, it's something that no one expect... I'll treat all tech versions as betas/alphas and stay on LTS when possible. It's impossible trusting in these versions, lots of weeks wasted here =/
     
  11. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    This was a change made as a bug fix for parented physics objects so likely a bug. Please file a report and post the case number.
     
    Marcos-Elias likes this.
  12. fahyc

    fahyc

    Joined:
    Nov 9, 2017
    Posts:
    1
    I ran into this problem too, and this script is our temporary fix - just put it on any rigidbodies that might be kinematic children of another rigidbody and it should work as expected again, though obviously I don't know your specific use case. It will also get position updates that were done during regular update though you may need to adjust execution order for this to work 100%.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class LameHack : MonoBehaviour {
    6.  
    7.     Vector3 localPosition;
    8.     Quaternion localRotation;
    9.     Rigidbody r;
    10.  
    11.     private void Start()
    12.     {
    13.         localPosition = transform.localPosition;
    14.         localRotation = transform.localRotation;
    15.         r = GetComponent<Rigidbody>();
    16.     }
    17.  
    18.     void Update () {
    19.         if (r.isKinematic)
    20.         {
    21.             transform.localRotation = localRotation;
    22.             transform.localPosition = localPosition;
    23.         }
    24.     }
    25.  
    26.     private void LateUpdate()
    27.     {
    28.         localPosition = transform.localPosition;
    29.         localRotation = transform.localRotation;
    30.     }
    31. }
    32.  
     
    Marcos-Elias likes this.
  13. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    136
    I had the same issue and worked it out with Unity, they have found it and hope to address it in 2018.3. The last build to have a stable parent/child rigidbody connection was 2018.1.5
     
    Marcos-Elias likes this.
  14. MoxenGames

    MoxenGames

    Joined:
    Oct 20, 2013
    Posts:
    8
    I am also experiencing this bug. I submitted a detailed bug report back in 2018.2.1f1. Case #1065432.

    My issue involves characters holding items, both of which have rigidbodies. After moving around, certain movements, especially sudden ones, offset the child from the parent.

    Possible important details:
    • Modifying the rigidbody of either the item (even when it's unparented), or the player rigidbody, fixes the issue, but ONLY when done in the inspector. So adding and then removing 0.01 mass to the rigidbody and then removing it within the inspector will fix it, but doing the same thing with a script does NOT. Therefore, I have not found a reasonable workaround (not parenting it would require rewriting a lot of stuff).
    • Rigidbody items placed in the scene manually do not have the issue.
    • Rigidbody items created through scripting via Instantiate...
      • DO have the problem when created after about 8 seconds (possibly because this is after the parent instantiates)
      • DON'T have the problem when created earlier (possibly before the parent instantiates)
    • The offset still occurred after every other script was removed from the item except for the rigidbody.
    The following quick video shows the issue and illustrates what I mean by items created later have the problem but items in the scene by default or created early on do not:

     
    Marcos-Elias likes this.
  15. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Same problem here: I have a camera that gets attached at start and if the vehicle is not perfectly still, it gets nudged away.
    My best guess is that there's a latency in attaching chilren now. Just one frame is enough to break the original position by a good amount, if an object is falling.
    The best solution I found for now is to not let my vehicle fall at start...
     
    Marcos-Elias likes this.
  16. ceebeee

    ceebeee

    Joined:
    Mar 7, 2017
    Posts:
    395
    Good News, I saw today that 2018.2.8f1 was released, with this in the Release Log:

    (1066072 (1059467)) - Physics: Fixed an issue where kinematic bodies may not follow transform change after setting its postion after setting their position or rotation via Transform component.

    Installed and tried it out, and sure enough this bug I was having with Invector is gone. I suggest people try this version and see if it helps them.
     
    Marcos-Elias and anthonov like this.
  17. Marcos-Elias

    Marcos-Elias

    Joined:
    Nov 1, 2014
    Posts:
    159
    Yes, confirmed! Fixed in 2018.2.8f1 and also on 2018.3 beta. Perfect.