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

Invalid AABB issue

Discussion in 'Physics' started by Terminus001, Jul 24, 2019.

  1. Terminus001

    Terminus001

    Joined:
    Nov 1, 2015
    Posts:
    121
    Hi everyone,

    In my project, I have a destructible glass panel. Originally, the glass is a single gameobject with a collider and no children. When hit by a rigidbody having a collider, the glass gameobject is replaced with a broken glass gameobject. This new gameobject has 80 or so children, each of which is a piece of (broken) glass having its own collider and rigidbody component.
    When testing, I realised that a few of these children, when falling down after the glass is broken, get NaN transform values, which in turn seem to cause this AABB issue.

    Can anyone point at the root of the problem, where I should look, what else I should read/learn and how this issue can be solved? I looked online, but people don't seem to have a solid fix to this.

    Thanks in advance!

    upload_2019-7-24_16-1-9.png
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,326
    I'm only guessing but are you allowing these glass rigidbody to fall forever and eventually they get way too far from the origin? If so, should they not be constrained/destroyed somehow?
     
  3. Terminus001

    Terminus001

    Joined:
    Nov 1, 2015
    Posts:
    121
    Hi,

    I have a terrain underneath them, so when they fall they hit the terrain collider and stay there. I did notice that a few of them actually pass through the terrain collider and continue below. So, just for a quick test, I placed another collider below the terrain to prevent them to continuously fall forever. This seems to block them, but I can't track all these rigidbodies because they are just too many. If one's transform goes NaN, I can't track it in the scene anymore.

    I want them not to get destroyed if they remain in the scene. But if they indeed trespass some colliders and fly away, perhaps I could destroy them if they get x magnitude away from a certain world position and see if that solves it..

    Thx
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,326
    Just a thought but if these are just debris then maybe you'd get better results and certain better performance if you used the particle system for this? You can continue to interact with colliders etc.
     
    Terminus001 likes this.
  5. Terminus001

    Terminus001

    Joined:
    Nov 1, 2015
    Posts:
    121
    I didn't know this could be done, thanks. I've never worked much with the particle system, but I'll take a look how I can do it using this method.

    Unfortunately the Destroy(gameObject) trick did not work. Even by destroying the gameobjects when further that 50 (magnitude) from the origin, the error still appears.. not sure why
     
  6. Terminus001

    Terminus001

    Joined:
    Nov 1, 2015
    Posts:
    121
    The issue with particles might be the fact that I cannot spawn them exactly in an orderly manner (see below)?

    upload_2019-7-24_17-52-55.png
    upload_2019-7-24_17-53-48.png
     
  7. Terminus001

    Terminus001

    Joined:
    Nov 1, 2015
    Posts:
    121
    I noticed something strange. Even if I destroy the gameobject when it gets too far from the origin, some of them manage to skip this command.

    upload_2019-7-24_18-0-35.png

    This image above shows a gameobject with a script that should destroy it when it gets too far from the origin, but it's still in the scene even if it has NaN transform values.

    I think that when instantiated, it might get thrown very far from the origin extremely quickly due to some overlap with the building collider perhaps..
     
  8. Terminus001

    Terminus001

    Joined:
    Nov 1, 2015
    Posts:
    121
    Nope, not even that. I'm out of ideas atm..
     
  9. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    @MelvMay how would one do that with a particle system?
    I'm doing basically what he's doing(only not with a glass pane), i use a particle system to add some effect to it, but how would you make the object into a particle system if each piece is a unique mesh and in a preset position/rotation, do I need to use a particle system for each piece?
    If so it seems not too far off from the rigidbody approach, altough profiling is needed to say.
    If not - then how?
     
    Terminus001 likes this.
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,326
    Note that I casually suggested the particle system for general glass debris before the above image was posted which looks like each glass shard is a unique mesh so that won't be easy with a particle system.
     
    Terminus001 and SparrowGS like this.
  11. Terminus001

    Terminus001

    Joined:
    Nov 1, 2015
    Posts:
    121
    Still haven't solved it. Any more ideas on this topic?
     
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,326
    I don't have any ideas beyond using the project and discounting things such as removing all collisions/interaction with the glass shards and seeing when the NaNs occur. Removing any scripts that interact with them too just in-case there's some div/zero or sqrt/minus values etc. The fact that you get it quickly after instantiating is telling (as you suggest) but you seem to have discounted a large collider moving it (although you shouldn't have such large colliders anyway) that would cause this kind of extreme positioning.

    It's nice to be able to change the behaviour as that can also be telling so maybe change the colliders to sphere/box colliders to see if it makes any difference. Also maybe try this with a single glass shard to see if it happens and dump its pose to see when it transitions to NaN.
     
    Last edited: Jul 29, 2019
    Terminus001 likes this.
  13. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    Just do a distance check on those glass shards to centre, and disable the gameobject + rigidbody if it is beyond a certain threshhold. That way itll disable itself before it goes too crazy high or low in value from origin.
     
  14. Terminus001

    Terminus001

    Joined:
    Nov 1, 2015
    Posts:
    121
    I had tried this approach, but for some reason it doesn't work if objects get pushed to NaN positions instantaneously..
     
  15. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,326
    If you can produce a simple reproduction case then feel free to zip it and upload it here and I can take a look or if it's private then send me a DM and upload it elsewhere.
     
    Terminus001 likes this.
  16. Terminus001

    Terminus001

    Joined:
    Nov 1, 2015
    Posts:
    121
    Ok I sent you the zipped file. Please let me know if you'll take a look and if you find the mistake.

    Rgs
     
    MelvMay likes this.
  17. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,326
    So I've been through and broke every single bit of glass I could find and I don't see any AABB errors at all in the console.

    I'm using 2018.3.14f1 but the project was last loaded in 2018.3.8f1 so I'll download that and give it a try there.
     
  18. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,326
    Using 2018.3.8f1 I get the error immediately so it seems maybe it was a bug that was fixed in a later version.
     
    Terminus001 likes this.
  19. Terminus001

    Terminus001

    Joined:
    Nov 1, 2015
    Posts:
    121
    Ahh I see.. I am in fact using 2018.3.8f1.

    Thanks for the help, will try downloading a newer version then!
     
  20. anatolyV

    anatolyV

    Joined:
    Nov 29, 2014
    Posts:
    63
    Have you tried something like this? You could also check x and z positions if you suspect the bodies are getting thrown sideways (could also do magnitudes like with the initial position check, but I'm not sure magnitude calculation would be alright for that).

    Code (CSharp):
    1. void FixedUpdate(){
    2.    if (transform.position.magnitude > 3000 || float.IsNaN(transform.position.y) || float.isInfinity(transform.position.y)){
    3.       transform.position = Vector3.zero;
    4.       rigidbody.velocity = Vector3.zero;
    5.       rigidbody.angularVelocity = Vector3.zero;
    6.       gameObject.SetActive(false);
    7.  
    8.       }
    9. }