I’m generating animations through script. During playback my rotation values have visual glitches, unless I assign the values through a Quaternion into LocalRotation, and then in the animation window change the rotation interpolation setting from “Quaternion” to “Euler Angles (Quaternion)”. The setting is in the picture provided.
I would like to be able to change this value through script for all rotations in the animation.
If anyone knows how I can access this through script I would greatly appreciate it.
My hunch atm is it’s something to do with AnimationUtility.PropertyModificationToEditorCurveBinding(); but even if that is right, I don’t know how to fill out the PropertyModification it requires to work. I don’t think it’s as easy as putting “Euler Angles (Quaternion)” into the PropertyModification.type.
Edit #1: (v---- Go to Edit #2)
I found a workaround that works for my situation.
When constructing the animation, instead of using m_LocalRotation or m_LocalEulerAngles, there is a third option m_LocalEulerAnglesBaked. This will apply the Euler Angles (Quaternion) interpolation to the animation curve.
Found the property by making a git commit, and then changing the attribute and looking at the git diff. It would be very difficult to change from Quaternion to Euler Angles (Quaternion) interpolation, because unity first converts the Quaternion into a Vec3 Euler and so you would have to make that change for every key frame, as well as changing some other settings.
Here is a forum post from 2015, that guided me to set the animation curve, instead of trying to modify the property:
If you’re in a situation where you already have the quaternion and need to change it into a Euler angle (quaternion) interpolation, I would probably sample the quaternion, reconstruct it as a Euler, then delete the old m_LocalRotation binding and apply a new m_LocalEulerAnglesBaked binding to solve this problem.
Edit #2:
If you use the LocalEulerAnglesBaked setting, the animation will play correctly, but will be almost 100 times the file size as it would be if you instead used the Quaternion binding, and then changed the interpolation to Euler Angles (Quaternion) in the Animation window inspector. so I’m back to considering this unresolved. I’ll just change the setting by hand a couple hundred times until I can think of a more clever way to fix this. Atm my main idea involves reading the git diff of the .anim file pre and post change, and then modifying the text file directly to mimic how it would be changed by the inspector.