Search Unity

Invalid parameter...infinity or nan. Help please.

Discussion in 'Scripting' started by Tester, Aug 30, 2009.

  1. Tester

    Tester

    Joined:
    May 24, 2009
    Posts:
    48
    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. :)
     
  2. Tester

    Tester

    Joined:
    May 24, 2009
    Posts:
    48
    I can post code if it would help anyone.
     
  3. Timmer

    Timmer

    Joined:
    Jul 28, 2008
    Posts:
    330
    Infinity or NAN values are caused by dividing by 0 and (a non-zero by zero or zero by zero, respectively).

    So I'd look for math operations in your code that could be diving by zero.
     
  4. Yorick2

    Yorick2

    Joined:
    Jan 24, 2009
    Posts:
    297
    I've also seen this happen with animationcurves which have illogical input (like all zeros).
     
  5. Tester

    Tester

    Joined:
    May 24, 2009
    Posts:
    48
    Thanks for the 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.
     
  6. CarlL

    CarlL

    Joined:
    Nov 11, 2008
    Posts:
    83
    I get the same error when I try to do this:

    Code (csharp):
    1. pHandL.animation[pRetinaDepressAnim1].normalizedTime = pDepressTime;
    even though all the variables trace out to good values, even when I hard code in the time to, say .5
     
  7. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    NaN... annoying little bugger.

    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!
     
    Last edited: Sep 3, 2011
  8. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    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?
     
  9. tayl0r

    tayl0r

    Joined:
    Jan 6, 2012
    Posts:
    85
    I'm using 3.5 and this problem still exists.
    Is there a good work around / some check I can do? I'm getting it just doing this:

    transform.rotation = Quaternion.Slerp(m_rotations[m_currentRotationFrom], m_rotations[m_currentRotationTo], m_currentRotationTime);

    where m_rotations is:
    m_rotations[0] = Quaternion.Euler(0f, 45f, 0f);
    m_rotations[1] = Quaternion.Euler(90f, 45f, 90f);
    m_rotations[2] = Quaternion.Euler(180f, 45f, 180f);
    m_rotations[3] = Quaternion.Euler(270f, 45f, 270f);
     
  10. TheAngrycrow

    TheAngrycrow

    Joined:
    Jun 16, 2013
    Posts:
    12
    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!
     
  11. TheAngrycrow

    TheAngrycrow

    Joined:
    Jun 16, 2013
    Posts:
    12
    This guy is right!
     
  12. silentslack

    silentslack

    Joined:
    Apr 5, 2013
    Posts:
    395
    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.
     
  13. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    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.

    I'm possibly seeing this bug:
    https://issuetracker.unity3d.com/is...hile-colliding-the-edge-of-another-gameobject

    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().
     
    Last edited: Jun 6, 2017
  14. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    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.
     
  15. marcelocoro17

    marcelocoro17

    Joined:
    Jan 9, 2019
    Posts:
    1
    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.