Problem restoring proper camera rotation

Hello. I’m using the following script to restore camera’s position and rotation after level editor reloads from the testing scene:

using UnityEngine;
using System.Collections;

public class LevEditCamPosInitializer : MonoBehaviour {

	// Use this for initialization
	void Start () {
		Debug.Log(LevEditGlobals.MainCameraPos);
		Debug.Log(LevEditGlobals.MainCameraRot);
		Debug.Log(this.gameObject.transform.rotation);
		Debug.Log("-----------------------------------");
		if (LevEditGlobals.MainCameraPos!=Globals.InfiniteVec3){
			this.gameObject.transform.position = LevEditGlobals.MainCameraPos;
		}
		if (LevEditGlobals.MainCameraRot!=Globals.InfiniteQuat){
			this.gameObject.transform.rotation = LevEditGlobals.MainCameraRot;
		}
		Debug.Log(LevEditGlobals.MainCameraPos);
		Debug.Log(LevEditGlobals.MainCameraRot);
		Debug.Log(this.gameObject.transform.rotation);
	}
}

InfiniteVec3 and InfiniteQuat are appropriately Vector3 and Quaternion initialized with all values set to Mathf.Infinity as I couldn’t check against/set to null due to both Quaternion and Vector3 being structs. Given both of these can’t “naturally” reach such value, this is a safe way to check whether they’ve been set properly.

Anyway, back to the problem at hand. The thing is that restoring position works just nicely, but it doesn’t restore rotation. I’m sure that MainCameraRot isn’t set to Globals.InfiniteQuat, as debug statements return valid one. First debug statement returns what was put into the LevEditGlobals.MainCameraRot, but the second always return (0.0, 0.0, 0.0, 1.0). I’m suspecting a clash with MouseLook script (using default one bundled with Unity, set to MouseXandY), which set rotation directly, but not sure how to fix it. Tried to play with script execution order, but no dice.

Any help? @Eric5h5 perhaps?

//edit: Here is exact debug log of this:

(Infinity, Infinity, Infinity)

UnityEngine.Debug:Log(Object)
LevEditCamPosInitializer:Awake() (at Assets/code/leveleditor/LevEditCamPosInitializer.cs:8)

(Infinity, Infinity, Infinity, Infinity)

UnityEngine.Debug:Log(Object)
LevEditCamPosInitializer:Awake() (at Assets/code/leveleditor/LevEditCamPosInitializer.cs:9)

(0.0, 0.0, 0.0, 1.0)

UnityEngine.Debug:Log(Object)
LevEditCamPosInitializer:Awake() (at Assets/code/leveleditor/LevEditCamPosInitializer.cs:10)

-----------------------------------

UnityEngine.Debug:Log(Object)
LevEditCamPosInitializer:Awake() (at Assets/code/leveleditor/LevEditCamPosInitializer.cs:11)


(Infinity, Infinity, Infinity)

UnityEngine.Debug:Log(Object)
LevEditCamPosInitializer:Awake() (at Assets/code/leveleditor/LevEditCamPosInitializer.cs:18)


(Infinity, Infinity, Infinity, Infinity)

UnityEngine.Debug:Log(Object)
LevEditCamPosInitializer:Awake() (at Assets/code/leveleditor/LevEditCamPosInitializer.cs:19)

(0.0, 0.0, 0.0, 1.0)

UnityEngine.Debug:Log(Object)
LevEditCamPosInitializer:Awake() (at Assets/code/leveleditor/LevEditCamPosInitializer.cs:20)

(after entering and exiting test mode)

(43.7, 10.1, -49.7)

UnityEngine.Debug:Log(Object)
LevEditCamPosInitializer:Awake() (at Assets/code/leveleditor/LevEditCamPosInitializer.cs:8)

(0.0, 1.0, 0.0, 0.1)

UnityEngine.Debug:Log(Object)
LevEditCamPosInitializer:Awake() (at Assets/code/leveleditor/LevEditCamPosInitializer.cs:9)

(0.0, 0.0, 0.0, 1.0)

UnityEngine.Debug:Log(Object)
LevEditCamPosInitializer:Awake() (at Assets/code/leveleditor/LevEditCamPosInitializer.cs:10)

-----------------------------------

UnityEngine.Debug:Log(Object)
LevEditCamPosInitializer:Awake() (at Assets/code/leveleditor/LevEditCamPosInitializer.cs:11)

(43.7, 10.1, -49.7)

UnityEngine.Debug:Log(Object)
LevEditCamPosInitializer:Awake() (at Assets/code/leveleditor/LevEditCamPosInitializer.cs:18)

(0.0, 1.0, 0.0, 0.1)

UnityEngine.Debug:Log(Object)
LevEditCamPosInitializer:Awake() (at Assets/code/leveleditor/LevEditCamPosInitializer.cs:19)

(0.0, 0.0, 0.0, 1.0)

UnityEngine.Debug:Log(Object)
LevEditCamPosInitializer:Awake() (at Assets/code/leveleditor/LevEditCamPosInitializer.cs:20)

As you can see, the rotation isn’t properly restored, though it is saved as it should before going into test mode.

Solved it. For some reason Quaternion doesn’t overload == operator properly, even though Vector3 does. I had to use Equals method instead. Unity should fix it for the sake of consistency.