Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Transform Position assign is not valid

Discussion in 'Scripting' started by rulan, Feb 1, 2019.

  1. rulan

    rulan

    Joined:
    Jun 20, 2013
    Posts:
    9
    Thank you in advance for your help.

    These are the main errors Im facing :

    [Error] transform.position assign attempt for 'char_ethan' is not valid. Input position is { NaN, NaN, NaN }:

    AnimFollow_PBC.AfterIK() Assets/PBC/AnimFollow_PBC.cs:462

    Code (CSharp):
    1.  460:   if (!this.lockSoftN && !this.lockSoftT)
    2. 461:   {
    3. -->462:       base.transform.Translate(-this.totalMassCenterError - vector2, Space.World);
    4. 463:       b9 = acc + b4 + b3;
    5. 464:   }
    6.  
    PBC._DoExecuteScripts_c__Iterator1.MoveNext() Assets/PBC/Main_PBC.cs:67
    Code (csharp):
    1.  
    2. 65:   }
    3. 66:   this.__f__this.ragdollControl.DoRagdollControl();
    4. -->67:   this.__f__this.animFollow.AfterIK(this.__f__this.moveClass.acc, this.__f__this.moveClass.deltaMouseRotation, this.__f__this.moveClass.effectiveUpLerped2, this.__f__this.moveClass.gravity, this.__f__this.moveClass.tiltPivot);
    5. 68:   if (this.__f__this.weaponAnimFollow)
    6. 69:   {
    7. [B][/B]
    8. SetupCoroutine.InvokeMoveNext()
    9.  
    SECOND TRANSFORM ERROR:

    [Error] transform.position assign attempt for 'char_ethan' is not valid. Input position is { NaN, NaN, NaN }.


    AnimFollow_PBC.BeforeMove() Assets/PBC/AnimFollow_PBC.cs:556
    Code (CSharp):
    1.  
    2. 554:       {
    3. 555:           velocity = this.ragdollCOMVelocity - this.yVel - this.xxVel;
    4. -->556:           base.transform.Translate(velocity * Time.fixedDeltaTime + this.y + this.xx, Space.World);
    5. 557:       }
    6. 558:   }
    7.  
    AdvancedMoveScript_PBC.MoveCharacter() Assets/PBC/AdvancedMoveScript_PBC.cs:336
    Code (csharp):
    1.  
    2. 334:   if (this.animFollow)
    3. 335:   {
    4. -->336:       this.velocity = this.animFollow.BeforeMove(this.velocity);
    5. 337:       this.relativeVelocity = this.velocity - this.onPlatformVelocity;
    6. 338:       this.relativeVelocity_n = Vector3.Dot(this.relativeVelocity, this.footIK.NRaw_Hat);
    7.  
    PBC._DoExecuteScripts_c__Iterator1.MoveNext() Assets/PBC/Main_PBC.cs:49
    Code (csharp):
    1.  
    2. 47:       return true;
    3. 48:   case 1u:
    4. -->49:       this.__f__this.moveClass.MoveCharacter(this.__f__this.nPC, this.__f__this.suspendMouse);
    5. 50:       if (this.__f__this.footIK)
    6. 51:       {
    7.  
    8. SetupCoroutine.InvokeMoveNext()
    9.  
    If more code is needed I have no problem sharing it, just ask for it.

    Heres also a screenshot of whats happening to my character ( WARNING: Funny) eed.png
     
    Last edited: Feb 1, 2019
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You have to figure out why the x,y,z fields hold NaN (Not A Number). This may need some digging with the debugger. and you have to check for operations that yield undefined results (that's one reason for NaN).
     
    rulan likes this.
  3. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,357
    Here is an article that explains what NaN means
    https://csharp.2000things.com/tag/nan/

    Most likely the actual line numbers in the error messages are not the problem. The error is just saying "Hey, you can't use NaN here." but the real cause of the error is "How and where did that NaN get there in the first place?" That probably happened somewhere else in the code and it may not be easy to find where, but it will have involved one of the floating-point variables in that line where the error occurred. I would put Debug.Log statements at various points in the execution to see if you have valid values.

    A possible cause could be that some value is set to 0 when it doesn't make sense for it to be 0. This can also happen if a variable is uninitialized.
     
    rulan and Suddoha like this.
  4. rulan

    rulan

    Joined:
    Jun 20, 2013
    Posts:
    9
    Thank you for asnwering, yeah, you are right, I suspect its either variables uninitialized or values set to 0... I will leave the two main files if you want to take a look, im honestly stuck.
     
    Last edited: Feb 7, 2019
  5. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,357
    That's a lot of code to go through, but take your first error for example- you have two variables, one is totalMassCenterError and the other is vector2. Before the line with the error, add a Debug.Log on each of these to see what the values are. If one of them is NaN, search through your code and find other places where values are assigned to that variable and add before-and-after Debug.Log at each of those places. Alternatively, use the Debugger like Suddoha suggested, and instead of Debug.Log, create break-points at these key places.