How to change rigidbody mass using AnimationCurve script

I was creating an animation using the scripting API, and I want to change the mass using the following:

public static function getGrowAnimation(go){
var curveX : AnimationCurve = AnimationCurve.Linear(0, go.transform.localScale.x, 5, go.transform.localScale.x*2);     

var curveY  : AnimationCurve = AnimationCurve.Linear(0, go.transform.localScale.y,5, go.transform.localScale.y*2);    

var curveZ  : AnimationCurve = AnimationCurve.Linear(0, go.transform.localScale.z, 5, go.transform.localScale.z*2);

var cMassCurve : AnimationCurve = AnimationCurve.Linear(0, go.rigidbody.mass, 5, go.rigidbody.mass*2);

var clip : AnimationClip = new AnimationClip();
clip.SetCurve("", Rigidbody, "mass", cMassCurve);
clip.SetCurve("", Transform, "localScale.x", curveX);
clip.SetCurve("", Transform, "localScale.y", curveY);
clip.SetCurve("", Transform, "localScale.z", curveZ);

return clip;
}

Where “go” is the game object, but the script doesn’t seem to work.

Then, in a script attached to the gameObject in question calls the above method:

var growthAnimation = AnimationClips.getGrowAnimation(gameObject);
animation.addClip(growthAnimation, "growthAnimation");

The transform animations work, my character is able to grow when the animation is called. But the rigidbody mass doesn’t double up.

Any thoughts?

The property is called m_Mass. You can query all the Animatable properties with an Editor script similar to this:

using UnityEngine;
using UnityEditor;

public class GetAnimatableProperties : EditorWindow
{
    GameObject obj;
    
    [MenuItem ("Animation/Get Properties")]
    static void Init () {
        GetAnimatableProperties window = (GetAnimatableProperties)EditorWindow.GetWindow (typeof (GetAnimatableProperties));
    }
    
    void OnGUI () {
        EditorGUILayout.PrefixLabel("Object");
        obj = (GameObject)EditorGUILayout.ObjectField(obj, typeof(GameObject));
        if (obj != null)
        {
            AnimationClipCurveData[] data = AnimationUtility.GetAnimatableProperties(obj);
            foreach(AnimationClipCurveData d in data)
            {
                EditorGUILayout.LabelField("Property", d.propertyName);
            }
        }
    }
}