- Home /
default(Quaternion) is not equal to itself when using equality operator
Quaternion defaultQuat = default(Quaternion);
Debug.Log(defaultQuat == default(Quaternion));
// always false
float defaultFloat = default(float);
Debug.Log(defaultFloat == default(float));
// always true
Quaternion defaultQuatTwo = default(Quaternion);
Debug.Log(defaultQuatTwo.Equals(default(Quaternion)));
// always true
wat
Answer by Shrandis · Dec 22, 2012 at 10:18 AM
I don't know much about the math involved and how exactly this causes that behavior, but:
Equals method checks the x,y,z,w values to return a result while the == operator checks for their dot products.
Answer by fuqunaga · May 30, 2014 at 04:19 AM
default() returns zero for value types.
but (x,y,z,w)=(0f,0f,0f,0f) is invalid value for quaternion.
their dot products is zero. so, == operator(checks dot products close to 1f) returns false.
if default(Quaternion) will be (0f,0f,0f,1f) then == operator will be true;
Your answer
Follow this Question
Related Questions
Quaternion.AngleAxis() is alway using the axis at 0, 0, 0 1 Answer
Set Quaternion Interpolation as default when creating animations? 0 Answers
Get my head around Unity Rotations 1 Answer
Rotation direction in coroutine 2 Answers
2D look at 1 Answer