- Home /
SceneCamera NAN persisting problem
Hey,
In our porject now we keep getting this error
transform.rotation assign attempt for 'SceneCamera' is not valid. Input rotation is { NaN, NaN, NaN, NaN }. UnityEditor.DockArea:OnGUI()
I know how to get rid of it, by either cloesing and reopning the sceneview or going to window->Layouts->Revert Factory Settings... Though it comes back everytime we play our scene. Does anyone have any clue to what it is that creates this error? Is there anything that is known to generate this error?
Kind Regards Alex
Edit:
I have figured out which script that is causing the problems.. If I remove it from the scene everything works fine and I don't get the SceneCamera error. But the script is so basic that I can't see how it would generate this error..
using UnityEngine;
using System.Collections;
public class CloudScriptHandler : MonoBehaviour {
public GameObject[] listOfClouds;
public Vector2 spawnTimeRandomSeeds;
public Vector2 cloudSpeedRandomSeeds;
public Vector3 positionMax;
public Vector3 positionMin;
float spawnTimer;
float timeToSpawn;
// Use this for initialization
void Start ()
{
timeToSpawn = Random.Range(spawnTimeRandomSeeds.x,spawnTimeRandomSeeds.y);
}
// Update is called once per frame
void Update ()
{
spawnTimer += Time.deltaTime;
if( spawnTimer >= timeToSpawn )
{
CreateNewCloud();
timeToSpawn = Random.Range(spawnTimeRandomSeeds.x,spawnTimeRandomSeeds.y);
spawnTimer = 0.0f;
}
}
void CreateNewCloud()
{
int maxRand = listOfClouds.Length - 1;
int randCloud = Random.Range( 0, maxRand );
GameObject clone;
clone = Instantiate( listOfClouds[randCloud], CalculatePosition(), Quaternion.identity) as GameObject;
clone.transform.parent = gameObject.transform;
clone.GetComponent<CloudScript>().cloudSpeed = Random.Range(cloudSpeedRandomSeeds.x, cloudSpeedRandomSeeds.y );
}
Vector3 CalculatePosition()
{
Vector3 newPosition = new Vector3();
newPosition.x = Random.Range( positionMin.x, positionMax.x );
newPosition.y = Random.Range( positionMin.y, positionMax.y );
newPosition.z = Random.Range( positionMin.z, positionMin.z );
return newPosition;
}
}
using UnityEngine;
using System.Collections;
public class CloudScript : MonoBehaviour {
public float cloudSpeed = 1.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
Vector3 newPosition = gameObject.transform.position;
newPosition.x -= Time.deltaTime * cloudSpeed;
gameObject.transform.position = newPosition;
if( newPosition.x <= -200 )
{
Destroy( this.gameObject );
}
}
}
Are you directly setting the sceneCamera's transform? Do you have this error on one machine with every project or with one project on every machine?
$$anonymous$$ight not even be that script that crashes itall just that it seems like it is this one since when i remove it never happens again..
First of all, thanks for moving the code to the question. I think you are the first one that actually changed the question :D.
As i said i don't see anything in those scripts that could cause that error. It seems that there's something messed up in the scene file. What if you "Revert Factory Settings" and then save your scene and project.
If that doesn't help you could try to copy the used prefabs and those scripts either into a new scene or a completely new project. If the error persists you should pack up an example project and file a bug report.
Answer by Bunny83 · Jun 20, 2011 at 01:48 PM
It sounds like you've messed up the quaternion values. Rotations in Unity are stored as Quaternions(wikipedia).
If you set x,y,z,w to illegal values that error could happen. Also if you set the eulerAngles to values outside of a full circle it will throw that error as well.
Don't set one of the members of a quaternion yourself. The 4 values (x,y,z,w) represent a normalized complex 4-dimensional equation. Use either transform.Rotate or create an absolute rotation with Quaternion.Euler.
edit
Just read that the error states that the SceneCamera is messed up... Do you use any editorscripts that access the scene camera?
Do you use Resources.FindObjectsOfTypeAll anywhere in your scripts? Because you have to be careful with that (like the docs already said). It returns ALL objects of that type, even the internal invisible GameObject that represents the SceneCamera.
I ain't touching the sceneCamera in any editorscripts anywhere.. and the only thing i do with Quaternions is that i instansiate a gameobject with Quaternion.identity.
How do you check for quaternion values that are valid? How to check if not NaN o.O
@ina: That's not really the question here since it's far more important to get behind the piece of code that makes the members of the quaternion "NotANumber". To check a float value against NAN see this question
Answer by looak · Jun 21, 2011 at 07:33 AM
So I've figured out what it was that caused the issue, but it still amazes me the results we get from this simple and very usual misstake. We had forgot to attach the CloudScript to the GameObjects that we were trying to instantiate. Doesn't make any sens to me why that would screw the SceneCamera but it did. Though the bug is gone now and we can continue developing our game with out this distraction.
Might not be the solution for others with the same issue but it was what caused it for us.
Regards,
Alex
Your answer
Follow this Question
Related Questions
2 Scripting Errors I need help fixing!! 3 Answers
Quaternion To Matrix conversion failed 1 Answer
Problem creating GUI.Window, Help please! 1 Answer
blackberry error (Author Id, etc...), no script added ye... 1 Answer
ArgumentException: Getting control 0's position in a group with only 0 controls when doing Repaint 0 Answers