Hello everybody,
I am currently playing around with the new timeline feature in unity.
What I am trying to do is to assign an AnimationClip(I recorded at runtime) to an object of the scene AND add it to the timeline.
Assigning the AnimationClip to the object through this code
PlayableDirector scenePlayableDirectorComponent;
AnimationClip clip;
Animator animatorOfSelected;
GameObject toAssignAnimationTo;
//get Animator of object to assign animationClip to
if (toAssignAnimationTo.GetComponent<Animator> () != null) {
animatorOfSelected = toAssignAnimationTo.GetComponent<Animator> ();
} else {
animatorOfSelected = toAssignAnimationTo.AddComponent<Animator> ();
}
//instantiate playable for animationClip
AnimationClipPlayable playable = AnimationClipPlayable.Create(scenePlayableDirectorComponent.playableGraph, clip);
//Create output for animator of object to assign animationClip to
AnimationPlayableOutput output = AnimationPlayableOutput.Create(scenePlayableDirectorComponent.playableGraph, toAssignAnimationTo.name + " output", animatorOfSelected);
//setSourcePlayable for output
output.SetSourcePlayable<AnimationPlayableOutput, AnimationClipPlayable> (playable);
works fine.
But I want the animation to appear in the timeline I created in the editor.
My approach is this:
GameObject toAssignAnimationTo;
PlayableDirector scenePlayableDirectorComponent;
//get timelineAsset from playableDirector
TimelineAsset timelineAsset = (TimelineAsset)scenePlayableDirectorComponent.playableAsset;
//create new animationTrack on timeline
var newTrack = timelineAsset.CreateTrack<AnimationTrack> (null, "Animation Track " + toAssignAnimationTo.name);
//bind object to which the animation shell be assigned to the created animationTrack
scenePlayableDirectorComponent.SetGenericBinding (newTrack, toAssignAnimationTo);
//create a timelineClip for the animationClip on the AnimationTrack
var timelineClip = newTrack.CreateClip (clip);
which seems to go into the right direction:
But the animation on “Cube” is not doing anything(the animations for “redCube” and “blueCube” were recorded in the editor, they work fine).
I hope somebody give me some advise,
Thanks in advance!