Search Unity

Bug 2021 -> 2022 Inertia Tensor Behaviour

Discussion in 'Physics' started by ColtonKadlecik_VitruviusVR, Oct 2, 2023.

  1. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    197
    Hey All,

    We recently updated from 2021 LTS to 2022 LTS (specifically 2021.3.6 -> 2022.3.10). Something between the 2 versions has changed and now all configurable joints used for VR grabbing behave/feel different... It feels like all joints are 'weaker'. Does anyone know if anything in the engine has changed that would effect this? Potentially something with the new physics simulation/timing setting?

    The project is fairly large and unruly so it has been hard for us to pin point an exact issue. We have also not had time to update a backup project 1 version at a time to find which version exactly breaks/changes everything but we will be doing that this week.

    I realize the question is pretty vague and without and any specifics is difficult to answer, just wondering if anyone has experience with this?

    Thanks!
    Colton
     
  2. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    197
    After testing on multiple versions of the editor we have determined that the issue is caused by modifying the inertia tensor of a rigidbody (maybe not working in 2022+?).

    I have created a test project that shoots a gun and measures the max bullet spread when impacting a wall. As you can see from the screen shot, when running identical projects in different versions of the editor we get very different spread. If I remove the script that changes the inertia tensor, everything goes back to roughly the same (spread force is random so will never be identical).

    [mod edit: do not post or share code from assets publicly]

    This issue affects all versions of 2022 (tried on 2022.1.0+). I have attached 2 sample projects for testing (2021.3.31 & 2022.3.10). Is this a bug or should I be changing the inertia tensor differently?

    Thanks!
    Colton
     

    Attached Files:

    Last edited by a moderator: Oct 27, 2023
  3. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    I'd try reducing the test project to a single case that shows the divergence consistently each time. For example, log the data of the bullets and the exact spread applied (the values applied to that impact), and take a single bullet that produces a huge spread on 2022. Applying the same data in 2021 should get the expected result. It should be reproducible every time. You may then try if modifying inertia differently could bring the expected result. Otherwise, you could file a bug with it.

    I've seen that your RigidbodyOverride script modifies the rigidbody properties one visual frame after it's enabled the first time (it won't re-apply the settings if it's disabled and re-enabled, see the actual order of execution of Unity's event methods here). This might be inconsistent physics-wise: once the script is enabled for the first time, quite a few frames (= Update cycles) may happen before the next physics update takes place. Only if, by mere coincidence, the corresponding physics update happens right after the script is enabled, then the overrides would be applied right after that physics update.

    This inconsistency might or might not be related with your issue. But if you're instancing stuff in runtime using these scripts, adjustments in the visual vs. fixed update cycles between Unity versions could be related to the issue. In one case, the new settings could be applied before resolving the forces or impulses in the rigidbody (= override values applied), and in the other case the settings would be applied after that (= override values ignored).
     
  4. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    197
    Hey @Edy,

    Just a quick update. I replied to your post approx. 2 weeks ago and for some reason the post got deleted. I submitted a bug to Unity and it has been confirmed as "Rigidbody component's values do not translate to the PhysX calculations when they are being overridden via a script" with bug ID UUM-55081.

    Cheers,
    Colton

    EDIT: Here's a link to the bug tracker https://issuetracker.unity3d.com/is...s-when-they-are-being-overridden-via-a-script
     
    Last edited: Oct 31, 2023
    Edy likes this.
  5. codebiscuits

    codebiscuits

    Joined:
    Jun 16, 2020
    Posts:
    91
    Hi,
    I've been interested in moving from 2021 to 2022, but am now worried:)
    Did the Unity folks explain exactly what was going on, so I can know if it's likely to be a problem for my game?
    Is it entirely just that setting the inertia tensor from a script doesn't work anymore (that's certainly going to cause a problem)? If so, is there a workaround (and is inertia tensor the only thing that's not working); if not, what's the issue?
     
  6. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    197
    They didn't really tell me too much. So far in our testing the only thing we have found is this inertia tensor issue. In 2022 they exposed some new Rigidbody fields (Center of Mass and Inertia Tensor). In our experience setting the tensor from a script or from the new field doesn't make a difference, they both behave differently than 2021. I have not found a work around yet. I have contacted Unity for more info and will update if I get a response.
     
    Edy and codebiscuits like this.
  7. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    This issue looks pretty serious. My vehicle physics packages rely on setting the center of mass and the intertia tensor of the rigidbody from scripting in order to configure the handling of vehicles properly. I'm on Unity 2021, but as for this, I should recommend my clients to stay at 2021 until this gets fixed.

    Maybe @MelvMay could bring some insights about if/how is this being addressed internally? I know you're a physics 2D developer, but I don't know who is currently in charge of 3D physics (is @yant still around?).
     
    codebiscuits likes this.
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,463
    @yant is still around yes and working on 3D physics. I can look at source and answer specific questions but honestly I know nothing about the change history above, sorry.

    EDIT: I'll ping him to see if he can offer insight here; looks like he's away at the moment though.
     
    Edy likes this.
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,463
    Looks like as of yesterday the case from 31st Oct (above) was bisected with initial findings pointing to an SDK update and is being investigated but that's provisional at best.

    Yant will clearly know more, he's the guru here!
     
    rdjadu, codebiscuits and Edy like this.
  10. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Thank you!
     
    MelvMay likes this.
  11. codebiscuits

    codebiscuits

    Joined:
    Jun 16, 2020
    Posts:
    91
    Hi,
    Is there any more information available about this?
    I'm using Edy's vehicle physics stuff which sets the center of mass and the intertia tensor of the rigidbody from scripting in order to configure the handling of vehicles properly.
    Does setting them just not work at all in 2022.3+?
    Or is it some weird edge-case?
    Is there some workaround?
    I'm interested in moving from 2021.3 to 2022.3 (nicer physics debug visualisation), but don't want to recommend it if inertia tensor isn't working.
     
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,463
    Looking at the moderation, it was reported that the code you uploaded to the forum is based off some physics asset here:
     
  13. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,463
    Looking at the case, it's been set to highest priority and was actively being looked at yesterday trying to bisect the issue AFAIK (from internal comments on the case).

    Just the messenger here though, that's all I know. :)
     
  14. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    197
    Hey @MelvMay, just wondering if you could provide a status update? I noticed the bug has been identified as a known issue in both the 2022.3.13 and 2022.3.14 release notes which seems promising.

    The only reason I am asking is because we are approaching the end of our development cycle and would like the begin beta testing with users at the start of 2024. We would really like to use Unity version 2022 for it's foveated rendering capabilities on PSVR2 but this inertia tensor bug makes it impossible as it greatly effects interacting with objects in game. Also, is it possible to test versions of the editor before it is released in the event that the bug does get resolved?

    Thanks!
    Colton
     
  15. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,463
    All I can say is that I can see it being actively worked on, various bisections and rabbit holes trying to find the exact cause.

    All I can do is look at the comments on the case and get a general sense of it being worked on. I fear getting pulled into knowing about this case when I absolutely don't. ;)

    I'd suggest asking via the incident you reported for more updates.
     
  16. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    197
    Sounds good, unfortunately I have been unable to access the bug report ever since filing it
     
  17. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,463
    I've messaged the devs on the case just to inform them of this thread but that's all I can do really.
     
  18. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    197
    Thank you kindly!
     
  19. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    Hey folks, I've been notified about this case indeed.

    Looking into this as a priority and I'm really sorry it's causing issues for your project.

    It's the very first report of this kind in 2022. From the brief looks I had so far it indeed appears that the behaviour difference came with the PhysX 4.1.2 update. I'm surprised to learn about it, as it's been out for a while.

    Thank you for your patience.
     
    Gooren, Edy, MelvMay and 2 others like this.
  20. sergio_cognata

    sergio_cognata

    Joined:
    Aug 1, 2017
    Posts:
    1
    Any update on this bug?
    Is there a planned fix version and release date?

    Thanks
     
  21. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    I'm stuck in 2023.1.20 I don't know what changed but my airplane game is heavily physics-based as you may guess and anything after that version creates all kinds of weird crap. I saw this bug reported over a month ago as a "known issue" but there is no fix yet. I hope we don't have to wait until 2024 to get this resolved because it's a serious bug.
     
  22. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    It's a tricky case, and we're looking into what in that PhysX update exactly triggered the observed difference. So far we've ruled out custom tensors, the issue will present itself even without them as long as we have certain ConfigurableJoints and AddForce. That's all I have at the moment.
     
  23. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    If it helps, to me it began happening on 2023.1.21.
    2023.1.20 seems ok. So it has to be a change between 20 and 21.

    I use AddForce and AddTorque in my game. My airplane flies straight at high speed in 2023.1.20, but when I move to .21, the airplane begins to fall and it is hard to maneuver as if the gravity vector is stronger or the inertia is messed up.
     
  24. PandaArcade

    PandaArcade

    Joined:
    Jan 2, 2017
    Posts:
    128
    @MelvMay @yant we are experiencing physics issues after updating to 2022.3.8, is this when PhysX was updated to 4.1.2? I posted something about it in another thread...
    I thought I would mention this here as I don't think configurable joints were the only part of Unity's physics that was negatively affected by the PhysX update. I did try to reproduce our issue in a simple project but haven't had any luck...
    I am continuing to test. I could submit our actual project as a bug report but I would rather not.
     
    Last edited: Jan 7, 2024
  25. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    any updates on this?
     
  26. Liam2349

    Liam2349

    Joined:
    Mar 10, 2016
    Posts:
    81
    PandaArcade likes this.
  27. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    oh boy, months and still not solved
     
    TNEdition likes this.
  28. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    Hello!

    Sorry for not coming to you sooner, things were happening rather turbulently lately.

    So looking into this particular case under a magnifying lens, it turns out that in the PhysX 4.1.2 they improved the TGS solver so that it doesn't loose that much energy as it used before. For that, it appears to be a change, but it's not a breakage, it's an improvement actually. It only seems to affect the TGS solver mode. Let me illustrate.

    Consider a cube on a spring joint like this one:



    Assume there is no damping:



    It appears that with the PGS solver, in both of the PhysX versions the cube’s trajectory decays even without any damping at all (damping inherent to the solver’s projections). Here is the first 10 seconds of the capture:


    However, with TGS there is some difference, as in the new PhysX 4.1.2 version TGS no longer decays that fast at all (the joint might appear weaker due to that?).


    If we were to repeat the same experiment with a spring joint that has some damping, here are the graphs we'd get.

    Again, in PhysX 4.1.1 there is no difference between PGS and TGS – they both get the same trajectory:



    In addition to that, PGS results in the same trajectories comparing 4.1.1 and 4.1.2. However, in 4.1.2 there is a difference between PGS and TGS.





    Hope that makes some sense now.

    Anthony
     
    Edy, Gooren and codebiscuits like this.
  29. Cloudwalker_

    Cloudwalker_

    Joined:
    Jan 3, 2014
    Posts:
    140
    What is being graphed here? Velocity? Is there zero drag on the rigidbody?
     
  30. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    Position along Y.
     
  31. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    i don't think that explains why gravity seems to pull objects differently. I also have no idea what's TGS and PGS. Where do i pick one or the other?
     
  32. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    You choose between PGS and TGS in the physics settings, check out the solver type drop down: https://docs.unity3d.com/Manual/class-PhysicsManager.html.

    Why do you say that you don't think that explains what happens? It's not exactly about the gravity or the complicated recoil logic as in the original report. It's pretty much about the behaviour of soft constraints - such as the ones used in the SprintJoint (it's just one of the simplest to use forms, but pretty much the same thing powers ConfigurableJoint and others). The way those constraints manifest their behaviour is via the impulses that the solver calculates in order to maintain the constraint. Clearly, different solvers will give different results. We show it with cube under gravity because it's clear that in nature there won't be any decay in this conditions under no drag and no damping.
     
  33. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    197
    Hey @yant,

    Thanks for looking into this. I can confirm that 2021 TGS -> 2022 PGS is similar enough that we can likely make it work. Is there a formula to calculating the amount of damping needed to get identical results from 2021 TGS -> 2022 TGS? Or is there other values I can change to go from 2021 TGS -> 2022 TGS?

    Thanks again,
    Colton
     
    Edy likes this.
  34. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    I'm afraid that I don't really have a formula to share at this stage, unfortunately.
     
  35. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Well, my settings are in PGS, and my airplanes are falling and behaving completely differently as soon as I switch from 2023.1.19 to anything above that version. That's why I say I don't think it is related. If i understood correctly, your post said PGS did not change.
     
  36. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    OK, I can't argue with that. It could very well be a totally unrelated problem. Do you have your project uploaded? Do you have a case#?