AnimationClip.SetCurve "localEulerAngles" not working

Hello everyone.

I have another issue with the SetCurve function.

I’m trying to set a rotation curve along the Z axis.

Here is my line of code:

clip.SetCurve("objectname", typeof(Transform), "localEulerAngles.z", rotZcurve);

The data I’m putting in the curve is defiantly not empty.

When I open the Animation editor (this has nothing to do with mecanim),

I get the “Clean Up Leftover Curves” Button.

When I click it, I see all the Z rotation I’m trying to do…

Any ideas why unity think my Z rotation is empty?

Thanks!

Edit

Appearntly it has somthing to do with EulerAngles.

As soon as a change to localRotation, the curve does appear.

The problem is, localRotation uses quaternions.

No matter what I tried to do, I always get the rotation jumping between -180,0 and 180…

Can anyone help me figure it out?

Figured it out.

Apparently, when setting a quaternion rotation, you need to provide the values for the vector4.

So here is what I did:

var rotXcurve = new AnimationCurve();
var rotYcurve = new AnimationCurve();
var rotZcurve = new AnimationCurve();
var rotWcurve = new AnimationCurve();

var angle = Quaternion.Euler(0, 0, NeededRotation);

rotXcurve.AddKey(Frame, angle.x);
rotYcurve.AddKey(Frame, angle.y);
rotZcurve.AddKey(Frame, angle.z);
rotWcurve.AddKey(Frame, angle.w);

clip.SetCurve(GO.name, typeof(Transform), "localRotation.x", rotXcurve);
clip.SetCurve(GO.name, typeof(Transform), "localRotation.y", rotYcurve);
clip.SetCurve(GO.name, typeof(Transform), "localRotation.z", rotZcurve);
clip.SetCurve(GO.name, typeof(Transform), "localRotation.w", rotWcurve);

Hope this will help anyone.

Instead, you can use the following property names to set the curve in euler angles like you were attempting to do originally.

localEulerAnglesRaw.x

localEulerAnglesRaw.y

localEulerAnglesRaw.z