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

Crazy rigid body tranform NaN error (not a divide by zero error)

Discussion in 'Scripting' started by brianasu, Apr 9, 2015.

  1. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    I've set up a car with a rigidbody and 4 wheel collider and it works great but then I randomly get

    transform.position assign attempt for 'Body' is not valid. Input position is { NaN, NaN, NaN }.
    (Filename: /Users/builduser/buildslave/unity/build/Runtime/Graphics/Transform.cpp Line: 904)


    I've checked my code and removed all the division and it still happens. I noticed it's completely random and the error cascades to all the other rigid bodies.

    The "Body" object transform is completely driven by the physics sim so I think it's an internal error. I just wanted to see if anyone has a solution or has the same problem.
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    sanity check, make sure all values have a default value.

    ie.

    float ThisVar = 0;
    Vector3 ForwardStuff = vector3.zero;
     
  3. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
  4. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Thanks for the advice and link I'll check those. It's just a bit of a worry since I'm not the one setting the position of the object. It's all based on a rigidbody. I never call transform.position = something
     
  5. Sycobob

    Sycobob

    Joined:
    Feb 1, 2013
    Posts:
    78
    @brianasu, were you ever able to find the source?
     
  6. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    WheelCollider.GetWorldPose was sometimes giving me NaN values so I had to put an if statement to check if the values were valid.