what does mean this error and how can i remove it?

Error:Invalid parameter pos in Collider.FetchPoseFromTransform because it was infinity or NaN

Script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Cubejump : MonoBehaviour
 {
     public GameObject maincube;
     private bool animate, jumped;
     private float scratch_speed = 0.5f, startTime;
     
     void FixedUpdate()
     {
         if (animate && maincube.transform.localScale.y > 0.4f)
         
             PressCube(-scratch_speed);
 
 
         else if (!animate) { 
         
             if (maincube.transform.localScale.y < 1f)
             
                 PressCube(scratch_speed * 3f); 
             
             else if (maincube.transform.localScale.y != 1.5f)
 
                 maincube.transform.localScale = new Vector3(1f, 1f, 1f);
 
         }
         if(maincube.GetComponent <Rigidbody> ())
         {
             if (maincube.GetComponent<Rigidbody>().IsSleeping() && jumped)
             {
                 print("Next One");
                 
                 maincube.transform.eulerAngles = new Vector3(0f, maincube.transform.eulerAngles.y, 0f);
             }
         }
     }
 
     void OnMouseDown()
     {
         if (maincube.GetComponent<Rigidbody>())
         {
             animate = true;
             startTime = Time.time;
         }
     }
     void OnMouseUp()
     {
         if (maincube.GetComponent<Rigidbody>())
         {
             jumped = true;
             animate = false;
             float force, diff;
             diff = Time.time - startTime;
             if (diff < 3f)
                 force = 190 * diff;
             else
                 force = 300f;
             if (force < 60f)
                 force = 60f;
             
             maincube.GetComponent<Rigidbody>().AddRelativeForce(maincube.transform.up * force);
             maincube.GetComponent<Rigidbody>().AddRelativeForce((maincube.transform.forward * -1 + maincube.transform.up).normalized * force);
         }
     }
     void PressCube(float force){
 
 
         maincube.transform.localPosition += new Vector3(0f, force * Time.deltaTime, 0f);
         maincube.transform.localScale += new Vector3(0f, force * Time.deltaTime, 0f);
     }
 }

This error means that somewhere in your code you placed a NaN or inf inside a vector3, and it ended up in the physics engine somehow.

NaN and inf values are usually obtained by dividing by 0, but other operations like Mathf.Sqrt(-1) will give a NaN.


I couldn’t find any place where you may be dividing by 0, however you are doing a lot wrong:

Since your cube is moved fully by hand, it should be a kinematic rigidbody, and you should call rigidbody.MovePosition and rigidbody.MoveRotation to change its transform, and NEVER modify the transform directly.

If you want collisions, it should be non-kinematic, and you should only call AddForce and/or set its velocity.

You are also using Time.deltaTime in a FixedUpdate, which won’t cause bugs, but is considered bad practice.