Edit to clarify this is not a generic coding question: I know what the NullReferenceException is referring to - obviously something that should be there is not there. I am asking very specifically about adding a curve to a clip in a timeline on a playable in Unity3d. I have indicated (possibly not clearly enough) that the script below correctly adds a clip (so NewCustomClip is correct and available) and that curve is there and correct (possibly I did not make this clear enough). In other words I believe I have all the correct objects addressed correctly but the curve is not being inserted and was looking for some advice from an expert with experience inserting curves into Unity3d timeline clips via C#. Thanks.
I have a CustomClip from a Custom Timeline Playable which controls blendshapes on a model. I can add curve keys manually but cannot add keys via script. So far I can add the clip via C#, set name and duration but the SetCurve function is throwing a NullReferenceException. Any thoughts would be greatly appreciated.
var newCustomClip = track.CreateClip<BlendShapesClip>();
newCustomClip.displayName = "My New Clip";
newCustomClip.duration = 10;
Keyframe[] keys;
keys = new Keyframe[3];
keys[0] = new Keyframe(0.0f, 0.0f);
keys[1] = new Keyframe(1.1f, 1.5f);
keys[2] = new Keyframe(2.0f, 0.0f);
curve = new AnimationCurve(keys);
newCustomClip.curves.SetCurve("", typeof(BlendShapesClip), "Blend Shapes Clip.Shape Weight", curve);