- Home /
prefab rotation changing after play (possible bug?)
Hello Unity,
Ok so I have a weird problem that can be reproduced easily, follow these steps and tell me if this is also happening to you:
1- create an empty object, reset transform 2- create another empty object as a child of the first one. (reset transform, at this point both of the objects have transforms at zero) 3- save this as a new prefab 4- now change the rotation of the child object to e.g. (-180, 0 , -18) on the prefab 5- hit start
for me after hitting start the rotation of the child object changes to (1.866934e-05, 180, 198) , I know you are thinking : 198 - 180 = 18, and 1.866934e-05 is a small number, but still I consider this as unintended behaviour, so can someone explain to me why is this happening?
cheers, Armin
Answer by wibble82 · Sep 05, 2015 at 10:30 AM
Hi Nefalia
This isn't really a solution for you, but it is the explanation :)
Like most game engines, unity doesn't really store the angles you see in the editor, which are 'Euler' angles - a 3d rotation expressed as a rotation about the x, y and axis. Euler angles are the easiest for a human to read, but actually incredibly awkward mathematically. They can express various orientations in odd ways, involve lots of trigonometry when combining them, and suffer from a problem known as gimbal lock. Sorry if knew all that and found it overly patronising! :))
Internally, the rotation is stored as a quaternion, which is really just an axis-angle rotation with some fancy math applied on top to make it more efficient.
What you are seeing is the result of unity converting your euler angles to a quaternion, applying the changes dictated through your scene setup, and then converting back to euler angles when displaying them to you. A small amount of precision is lost in this process because trigonometry is being performed to do the conversion which is only ever an approximation, however it shouldn't be anything to worry about, because:
firstly, its very very small!
secondly, mathematically unity is still working with the quaternions, so the bulk of the precision loss is only in what it displays to you.
Hope that helps!
-Chris
Answer by Dave-Carlile · Sep 04, 2015 at 09:24 PM
Unity normalizes angles so they are (I believe) between 0 and 359 degrees. The "small number" is just some rounding that happens after the math. It is the equivalent of 0.
If thats the case then -18 should be translated to 342, or I suck at math!
Your answer
![](https://koobas.hobune.stream/wayback/20220612002620im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
problem with make gameobject prefab 0 Answers
Prefabs spawn with wrong values 0 Answers
Instantied GameObject Prefab doesn't have a height 0 Answers
How to convert gameobject into prefab at runtime? 2 Answers
Unity Programmatically Link Prefab 2 Answers