Can't set Y rotation to zero with Quaternion.Euler

Y tilt usually is very small <0.1f. I want to set it to 0.


        public void OnObjectSpawn()
        {
            speed = GetComponent'<'Missile'>'().speed;
            if (transform.rotation.y != 0)
            {
                transform.rotation = Quaternion.Euler(transform.rotation.x, 0, transform.rotation.z);
            }
            speedV3 = speed * transform.forward + shipSpeed;
         }

What am I doing wrong? SpeedV3 just goes up by Z axis after script runs and sometimes a little ±X or ±Y. e.g. [0, 2.212974e-07, 75].

If i set:

transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z);
  • everything is fine. But if i set:
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, 0, transform.rotation.eulerAngles.z);
  • it brokes.

I moved rotation setting to IEnumerator WaitForEndOfFrame and now everything is fine.