Search Unity

Bug Intermittent "Infinity or NaN floating point numbers"

Discussion in 'Physics' started by mons00n, Jun 3, 2023.

  1. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    304
    Every entity in my game has a 0.25 radius spherical collider (with kinematic rigidbody) spawned with it on the server (the collider object is a prefab set as a child of the entity's transform). It is on a dedicated layer and is only used for detection purposes. However, on very rare occasions (we have encountered this issue less than 5 times since October of 2022) the server starts to spam the following error until the server executable is restarted.
    Code (CSharp):
    1. Infinity or NaN floating point numbers appear when calculating the transform matrix for a Collider.
    The hierarchy path attached to the error shows that the collider in question is different every time this has occurred, which indicates to me that it is not unique to a specific entity spawn (reminder that the detection collider is a prefab used by all spawns). The problem I am facing is that the presence of this collider intermittently causes any Physics.OverlaphSphere calls to return incorrect results; players end up missing out on character experience, loot rolls, and the like.

    The only related thread I could find suggests that you disable AutoSyncTransforms - which is already disabled in my project.

    Any ideas on why this might randomly happen? Or how to prevent it from occurring? This issue is extremely disruptive to gameplay when it occurs, even if that is infrequent. Our server executables are currently running on a 2021.3.22f1 headless linux build.
     
    paulatwarp likes this.
  2. paulatwarp

    paulatwarp

    Joined:
    May 17, 2018
    Posts:
    135
    I am also seeing this error on Unity 2021.3.21f1 and Unity2021.3.16f1 but only on the Xbox platforms and only after some 180 or so iterations - never on Windows PC versions as far as I can tell. AutoSyncTransforms is disabled on all platforms.
     
  3. paulatwarp

    paulatwarp

    Joined:
    May 17, 2018
    Posts:
    135
    I'm trying to create a small project to repro the bug, but so far, no luck.
     
  4. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    304
    On one hand I'm relieved it's not just me. On the other hand I have little hope of this being resolved. My project is unfortunately too big to even attempt a repro project :( Good luck with yours I hope for both our sakes you can find a way to repro it!
     
    paulatwarp likes this.
  5. paulatwarp

    paulatwarp

    Joined:
    May 17, 2018
    Posts:
    135
    I don't have anything definitive yet, but it might be something to do with Unity re-cycling a transform component on a recently deleted object. My best hope at the moment is to find a workaround because a fix would likely require updates that would massively impact the cost of a patch.
     
    mons00n likes this.
  6. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    304
    Interesting. Well if you come up with something I would love to hear about it!
     
    Paul-Sinnett likes this.
  7. paulatwarp

    paulatwarp

    Joined:
    May 17, 2018
    Posts:
    135
    I think I have a repro case:

    RigidbodyBug on github.com

    For me, on PC builds, this works fine. But on Xbox I get the Infinity or NaN message and the objects don't show. I'd be interested to see if you get the same result on Linux.
     
    Zimbres likes this.
  8. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Interesting, it seems the moment when transform changes are synced to rigid body/colliders is different across platforms.

    Still, my heart skipped a beat when I read "The prefab is inactive and the scale is zero". That's pretty much asking to get NaNs and Infinity values down in the physics system, alongside with objects that fell through the ground, were never destroyed and fall for long enough until their velocity become gigantic.

    One issue with NaNs and Inf is that they can be "infectious" and the effect shows up far away from the cause.
     
    Paul-Sinnett likes this.
  9. Paul-Sinnett

    Paul-Sinnett

    Joined:
    Nov 12, 2010
    Posts:
    27
    Yeah, it's a game where objects start at zero size and then scale up as they grow. I think 0.01 scale might work as a workaround, but I haven't tested it yet.
     
  10. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    304
    Opening the RigidbodyBug scene and pressing play yields the following error spam in the editor:
    Skipped updating the transform of this Rigidbody because its components are infinite. Could you have applied infinite forces, acceleration or set huge velocity?

    I get the same for both macOS (apple silicon) and linux editors (my windows box is unfortunately tied up with builds but I can try it tomorrow).

    I did some tinkering and found that if I set
    transform.localScale = Vector3.one
    just after the rigidbody is added but before the game object is activated then everything works fine.
     
    Last edited: Jun 23, 2023
    paulatwarp likes this.
  11. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    304
    Setting the prefab to 0.01 does appear to fix it on my end. None of the prefabs in my project should ever hit a 0,0,0 scale though, so I'm wondering if this is a true repro case? Either way it is odd that different platforms treat it differently.
     
    paulatwarp likes this.
  12. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    304
    I can confirm that your project indeed works fine on windows and spews errors on macOS & Linux. Absolutely worth submitting!
     
  13. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Yeah, submit as a bug. Whether it works or spews errors, it should be consistent on all platforms.
     
    mons00n likes this.
  14. paulatwarp

    paulatwarp

    Joined:
    May 17, 2018
    Posts:
    135
    I have submitted a bug so hopefully this will be resolved in future Unity versions. Fingers crossed any fix will fix the other issue too. The reason it was so intermittent for me was that the growth rate is random and (on rare occasions) the scale can be zero on the first frame after the object is created. Clamping the scale to a minimum of 0.01 seems to be a reliable workaround in my case.
     
  15. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    304
    Did you ever hear anything back on this?

    I'm still encountering my issue on 2021.3.30f1 :(. Anyone at @Unity have any thoughts?
     
    paulatwarp likes this.
  16. paulatwarp

    paulatwarp

    Joined:
    May 17, 2018
    Posts:
    135
    Only that it has been confirmed as a bug.
     
  17. paulatwarp

    paulatwarp

    Joined:
    May 17, 2018
    Posts:
    135
    Marked as won't fix: