Search Unity

The dreaded invalid AABB errors

Discussion in 'Physics' started by JohnRossitter, Mar 27, 2017.

Thread Status:
Not open for further replies.
  1. JohnRossitter

    JohnRossitter

    Joined:
    Dec 18, 2013
    Posts:
    1,027
    So, my team has been struggling with this for a while now.
    We have an issue with Unity instantiating prefabs which causes the physics engine to crash.
    I was able to finally isolate the issue this weekend and I wanted to share the cause here incase anyone else has it happen.

    What happens:
    After about 10 minutes of gameplay, our game will suddenly have all rigidbody gameobjects crash, and throw thousands of errors into the console, often crashing the editor completely. What is important here is that the problem does not present itself immediately, but rather after about 10 minutes play. I'm not sure if its a memory leak or some other hard limitation that we are hitting but we can let our character sit idle for 10 minutes and only spawn a single instance of our troubled prefab after 10 minutes and crash. This effects both the Editor and compiled versions as well. We use Unity 5.5.1 64 bit on both MacOS and Windows.


    The cause:
    In our case this was being caused when we instantiate prefabs/resources which contain child objects that contain their own physics properties. For example, we spawn up a new instance of a prefab like this:
    RootObject
    ----Child 1 (rigid body & mesh collider)
    ----Child 2 (rigid body & mesh collider)
    ----Child 3 (rigid body & mesh collider)
    ----Child 4 (rigid body & mesh collider)
    ----Child 5 (rigid body & mesh collider)

    The resolution:
    Instead of creating instances which have one object that contains many preset child objects with their own physics properties, we changed the spawning code to just create the individual child objects instead. While this was not an ideal solution for us, and it took many many wasted man hours to finally resolve the issue, its the solution we are going to stick with for now.

    What needs to happen:
    Someone at Unity needs to research this and see what the underlying cause is.
    Sadly, invalid AABB errors give no real context as to what is happening, and when it happens, it crashes the entire physics engine at once and there is no good information on how to diagnose the issue. If someone from the physics team would like to reproduce the issue, I have my project up collaborate and they can deep profile a copy if they like.
     
  2. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    983
    Out of curiosity, do you have any particle systems attached to the GameObjects that may be throwing this?
     
    JohnRossitter likes this.
  3. JohnRossitter

    JohnRossitter

    Joined:
    Dec 18, 2013
    Posts:
    1,027
    Nope, not a single one
     
  4. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    983
  5. JohnRossitter

    JohnRossitter

    Joined:
    Dec 18, 2013
    Posts:
    1,027
  6. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,518
    If your rigidbodies do something 'illegal' the system can explode. I usually see this happen when something clearly goes wrong, bodies are intersecting, flying all over the place, etc. Reducing the cases where this happens will help take care of the issue.
     
    JohnRossitter likes this.
  7. JohnRossitter

    JohnRossitter

    Joined:
    Dec 18, 2013
    Posts:
    1,027
    In our case we were creating instances of a prefab that released about 20 falling leaf objects from a tree.
    It worked flawlessly up until the 10 minute mark, and then unity just sh^&s the bed.
    I was able to reproduce this with simple cubes as well.
    Unity just does not like spawning instances up of prefabs that have child physics objects.
     
  8. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    983
    So a few questions to consider:
    1) I'm assuming you're not doing anything silly like attaching a rigidbody to the parent, correct? That is a big no-no.
    2) Is it possible to simply spawn the child objects at the root of the scene hierarchy? If the only thing you get from making them children is some runtime organization then that seems like a fair trade off if it will stop the errors.
    3) Are you spawning from a pool? Do any physics properties change during runtime? Either of these might indicate you have some kind of race condition where the rigidbody starts running before the colliders have a chance to change to the desired state.

    Wish I could give an actual answer but you'll have to make due with some probing questions, sorry.
     
    JohnRossitter likes this.
  9. JohnRossitter

    JohnRossitter

    Joined:
    Dec 18, 2013
    Posts:
    1,027
    Heya
    Thanks for posting some questions, Ill answer them below.

    1) No the parent game object is simply a container transform with no other components on it.
    In my case what I am doing is instantiating a cherry bloom with about 32 individual leaf objects.

    2) Thats what Im actually doing now.

    3) I have tried the setup using both pooled and non pooled approaches with the same results.

    Again what's very strange about the whole thing is that I can spawn hundreds of these and its fine. But after about 10 minutes of gameplay spawning anything will crash. Be it if it's my 101th or 1st. That's the weird thing about it.
     
  10. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    983
    Yeah, this does sound strange. If you haven't already, you might consider filing a bug report and post the issue number here.

    One last suggestion to narrow things down: try removing the collider, then the rigidbody, and then both from the prefab and see if that makes a difference.
     
    JohnRossitter likes this.
  11. JohnRossitter

    JohnRossitter

    Joined:
    Dec 18, 2013
    Posts:
    1,027
    Yeah it only happens when there is a collider and rigidbody on the child objects.
    Sadly my project is so large there is no practical way to share it in a bug report, which is why i offered to let Unity access it via Collaborate :)
     
  12. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,260
    I was getting this error and found I was instantiating a physics object in the same place as another. Adding 0.05f to my y axis on spawn fixed this for me.
     
    JohnRossitter likes this.
  13. JohnRossitter

    JohnRossitter

    Joined:
    Dec 18, 2013
    Posts:
    1,027
    Thanks for the feedback, sadly this is not the same issue as mine :(
     
  14. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,260
    Damn. Hope you find the cause soon.
     
  15. DamonJager

    DamonJager

    Joined:
    Jul 16, 2015
    Posts:
    56
    I don't know if it has to do with hierarchies. Some time ago I managed to skip the problem, I stopped feeding back some values (output arrays to input arrays) to an evolutive RNN which is referenced by an executor gameobject and a trainer class in another gameobject. Also, the trainer called a function that resided inside the excecutor gameobject that reseted it's rigidbodies to their original positions, rotations, and speed/angularspeed (zero). Also, the RNN got its float[]s filled with nan values.

    TCDR, I can't be more precise, but the overall idea is that it's not just the hierarchies.
     
    Last edited: Apr 6, 2017
  16. Linus

    Linus

    Joined:
    Feb 22, 2012
    Posts:
    112
    Fibonaccov likes this.
  17. shreedx

    shreedx

    Joined:
    Feb 7, 2018
    Posts:
    4
    We are having the exact same issue in our project, were you able to fix this issue @JohnRossitter ?
     
  18. Linus

    Linus

    Joined:
    Feb 22, 2012
    Posts:
    112
    My last post did not work for me. I sent a bug report, but they could not replicate it on their machine.
    But they did suggest to try Legacy Contact Generation. And yes it seems like the legacy setting does make bug go away for me.

    Do send them a bug report if you can. The more reports the more chance they have to track down the bug.

    However here is a script you can customize to track down the bug or perhaps simply workaround it. I did not notice any side affect from enabling autoRecover on this script.

    Hope it helps.

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class AABBDebug : MonoBehaviour {
    7.  
    8.     public AABBDebugSetting setting;
    9.  
    10.  
    11.     public Vector3 lastRecordedPosisiton;
    12. []
    13.     public List<Vector3> recordedPositions = new List<Vector3>();
    14.  
    15.     private void LateUpdate( )
    16.     {
    17.        
    18.         if( float.IsNaN(transform.position.x) )
    19.         {
    20.             UnityEngine.Debug.LogWarning( "pos is nan " + GetComponent<Rigidbody>().velocity, gameObject );
    21.             if ( setting.pauseGame ) Time.timeScale = 0f;
    22.             if ( setting.autoRecover )
    23.             {
    24.                 GetComponent<Rigidbody>().velocity = Vector3.zero;
    25.                 GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
    26.                 transform.localPosition = lastRecordedPosisiton;
    27.                 GetComponent<Renderer>().material.color = setting.colorAfterRecover;
    28.             }
    29.  
    30.             if( setting.pauseEditor ) UnityEngine.Debug.Break();
    31.             return;
    32.         } else
    33.         {
    34.             lastRecordedPosisiton = transform.localPosition;
    35.         }
    36.         if ( !setting.recordPastFrames ) return;
    37.         if(recordedPositions.Count == 0 )
    38.         {
    39.             recordedPositions.Add( transform.localPosition );
    40.             lastRecordedPosisiton = transform.localPosition;
    41.             return;
    42.         }
    43.         if(
    44.             transform.localPosition.x != recordedPositions[recordedPositions.Count - 1].x
    45.             ||
    46.             transform.localPosition.y != recordedPositions[ recordedPositions.Count - 1 ].y
    47.             )
    48.         {
    49.             recordedPositions.Add( transform.localPosition );
    50.  
    51.         }
    52.  
    53.         if ( recordedPositions.Count > 200 ) recordedPositions.RemoveAt( 0 );
    54.  
    55.     }
    56. }
    57.  
    58.  
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. [System.Serializable]
    6. [CreateAssetMenu( menuName = "Debug/ABBB Setting" )]
    7. public class AABBDebugSetting: ScriptableObject
    8. {
    9.  
    10.     public bool autoRecover = true;
    11.     public Color colorAfterRecover;
    12.     public bool recordPastFrames = false;
    13.     public bool pauseEditor = true;
    14.     public bool pauseGame = false;
    15. }
    16.  
     
    Fibonaccov likes this.
  19. PiotrZdanowski

    PiotrZdanowski

    Joined:
    Jun 15, 2018
    Posts:
    4
    Haven't seen if You did talk about this but: I got this error when I tried to SetDestination() of a NavMeshAgent to a Vector3 of (NaN, NaN, NaN).
     
    LuckyMisterSleven likes this.
  20. ChrisWalsh3

    ChrisWalsh3

    Joined:
    Mar 30, 2016
    Posts:
    6
    also gives this error if you set the position of a UI element to -+ infinity ... just putting that here for any future searchers!
     
    OVIOAli and LuckyMisterSleven like this.
  21. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    I have been trying to create my own version of https://github.com/umiyuki/HumanoidHandPoseHelper with "Load Clip" and "Save Clip" buttons - it reads off the time zero values for properties in the clip assuming that is all that is in the clip. Somewhere along the line it started returning NaN when trying to load a clip (a separate script to print out values in the clip does not return NaN). I don't have any nested prefabs. There is a single character (a prefab) in a scene with a single rectangle for the ground (created using VRoid Studio, loaded using UniVRM).

    Today when i loaded the project back up to give it another go, I started seeing

    Invalid AABB aabb
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr, Boolean&)

    I probably have a bug in the script somewhere, or violating some internal contract, but no idea what it is. Reporting in case useful on this thread. I don't have any particles, nested prefabs, etc. Going to dig a bit more giving up until tomorrow.
     
  22. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,823
    Ahhhhh! :mad: I've been pulling my whole project apart for the last few days and I can't for the life of me figure this out.
    Is there any way to find out what actual object it's coming from?
    Screen Shot 2021-03-30 at 2.53.39 pm.png
    I'm slowly stripping everything out of my project and it's really exhausting.
     
  23. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,823
    Ok well it seems the problem might have been due a particle system that was in my scene and has been without causing an issue for the last few years, not sure why it broke things, and for the love of all things holy why couldn't they point to the object in the error o_O !
    I know John didn't have any particles in the scene but I just thought I'd add this for anyone else stuck like I was... (Probably future me).
     
    oAzuehT likes this.
  24. Mithri1

    Mithri1

    Joined:
    Mar 9, 2014
    Posts:
    1
    My guess is that you're sending in a NaN into transform.SetPositionAndRotation etc..
     
    Whatever560 likes this.
  25. manu6366

    manu6366

    Joined:
    Mar 12, 2021
    Posts:
    2
    I also facing this issue and the issue was in my ui image's local scale. So solved it by changing from localscale to fill amount for progress bars..
     
  26. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    I've locked this thread because this error can be caused by lots of non-physics-related things. It's all related to bad Transform values.
     
Thread Status:
Not open for further replies.