Getting error transform.position assign attempt for "Player" is not valid on rigidbody

I’ve seen others ask about this error and some say it appears in the editor only, some say it’s because 1 or more of the Vector3 values is null.

I can see in the debug that my project thinks the x and z values are null - but I don’t understand why, this is a rigidbody and I don’t calculate the Vector3 through my code. I use AddRelativeForce() & AddRelativeTorque()

alt text

This error occurs when my player hits a wall in a specific part of a specific level. Could it be related to the bounce texture I have on my level mesh maybe? Honestly got no idea.

Edit: kmgr wanted to see code so here’s the most relevant bit. Like I said, I don’t edit the Player’s transform directly. Only the rigidbody.

function FixedUpdate () {

	var moveHorizontal : float= Input.GetAxis ("Horizontal");
    var moveVertical : float= Input.GetAxis ("Vertical");
    
		if((moveHorizontal < 0) || Input.GetKey("a"))
		{
			GetComponent.<Rigidbody>().AddRelativeTorque (0,-rotationSpeed,0);

		} else if((moveHorizontal > 0) || Input.GetKey("d"))
		{
			GetComponent.<Rigidbody>().AddRelativeTorque (0,rotationSpeed,0);
		} 
		
		if ((moveVertical > 0) || Input.GetKey("w"))
		{

			GetComponent.<Rigidbody>().AddRelativeForce (Vector3.forward * speed);

		} else if ((moveVertical < 0) || Input.GetKey("s"))
		{ 
			
			GetComponent.<Rigidbody>().AddRelativeForce (Vector3.back * speed);
		}
}

I’VE SOLVED IT! I experimented disabling scripts, doing lots of weird things to figure this out. I noticed it always happened when my player collided with a certain place on the level mesh. So I played with mesh import options and changed the Mesh Compression from “off” to “Low”…

And it’s now fixed. What an odd bug!
Took me a long time to debug this too. Thanks everyone who commented!

So, the problem is likely in your speed or rotationSpeed variable. If either of them are NaN (Not a Number), then that will ruin the valid numbers in the rigidbody, causing the bug you are experiencing. If I were you, I’d go through the logic that computes those variables, especially divisions, to make sure they aren’t dividing by zero or using imaginary math (X ^ -1, etc).

Short of that, you can simply sanitize your inputs by not calling those AddForce functions if Single.IsNaN() returns true.