I am trying to load my game and the console throws a bunch of these errors:
“Invalid parameter because it was infinity or nan.
UnityEngine.GameObject:AddComponent(String)
UnityEngine.GameObject:AddComponent(String)
UnityEngine.GameObject:AddComponent(Type) (at C:\builds\unity-branches-2.5.x\unity-2.5.x\Runtime\Export\Generated\BaseClass.cs:351)
beacon:buildnew() (at Assets\assets1\beacon.js:46)
UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
UnityEngine.MonoBehaviour:StartCoroutine(String) (at C:\builds\unity-branches-2.5.x\unity-2.5.x\Runtime\Export\Generated\BaseClass.cs:789)
$:MoveNext() (at Assets\assets1\beacon.js:101)”
The game still loads and plays.
I can get it to stop if I slow down my coroutines with yields but that makes it load really slow and doesn’t always work.
I thought it strange its calling the error on AddComponent. Is it normal for code to go ahead before some functions complete? Maybe it hasn’t registered the gameobject I made just before it yet.
I wonder if I could ignore it and just add a 2 second or so pause after all is loaded for things to catch up. Because maybe unity redoes the line when it gets that error and that’s why my game still plays.
Anyone had trouble like this before? Would appreciate any help.
I replaced my code to rebuild a mesh from scratch with code to instantiate a prefab and it solved it. May not be a workaround for everyone but might help someone.
Tell me one thing: Why didn’t the Unity guys program the debug versions of their code (IE ToAngleAxis) so that if the operation results in retard values like NaN or an Infinity it causes a debug break? Now, I have to search for the damn thing manually. Common sense people!
Yep. It turns out it was Unity’s AngleAxis function which caused the error. Having a Quaternion of 0,0,0,-1 convert into an AngleAxis causes the resulting axis to be retard values. Honestly, put a catch for these things in 3.5? Pretty please?
So! It looks like this error still comes from rotation manipulation. That makes a lot of sense… I’m using 4. I’ll have to re-arrange my Instantiate() in order to fix this ! Thanks!
Is there any way to pin down what is the offending line? I’m receiving this error, it seems to happen on physics collisions but can’t pin down why exactly.
I too am getting it on collisions. It’s very infrequent. The position on the transform is NaN but everywhere in code i’m setting that value I’m doing a NaN check first. There might be some strangeness happening in mesh colliders or possible because i’m manipulating a rigid body out of fixed update, setting its velocity to zero and moving it via the transform… I know, I know, all bad things to do… Still annoying that it results in inconsistent untraceable NaNs though.
It might have something to do with scaled mesh colliders? that’s what my rigidbody is colliding with when sometimes get a NaN transform in OnCollisionEnter().
Update. Changing either of the mesh normals to calculate or changing the scale of the mesh collider object both stopped the issue for me… but I’m guessing it has only cosmically aligned the universe just right to get past that one specific case. This seems like a pretty bad issue to me. I’ll try and create a simple reproduction scene and submit a bug to unity.
In Screen Space Camera mode, if you put a canvas on position (0,0,0) then all the elements inside the canvas will get position NaN, which destroyed my Project. The solution was to remove the canvas from the scene and replace it with a backup, if there’s no backup you’re screwed I guess.