Search Unity

Need a way to Copy RecordableClip in AnimationPlayableAsset in timeline's AnimationTrack

Discussion in 'Timeline' started by Suika, Jan 20, 2018.

  1. Suika

    Suika

    Joined:
    Nov 19, 2013
    Posts:
    33
    My copy tool is nearly done, only AnimationTrack with RecordableClip has problem,

    My code is Right below :


    void CopyAnimationTrack()
    {

    AnimationTrack originAnimationTrack = originTrackAsset as AnimationTrack;
    newTrackAsset = newTimeLine.CreateTrack(originAnimationTrack.GetType(), parent, originAnimationTrack.name);

    AnimationTrack newAnimationTrack = newTrackAsset as AnimationTrack;
    IEnumerable<TimelineClip> clips = originAnimationTrack.GetClips();
    IEnumerator iEnumeratorOfClips = clips.GetEnumerator();
    while (iEnumeratorOfClips.MoveNext())
    {
    TimelineClip originTimelineClip = iEnumeratorOfClips.Current as TimelineClip;
    TimelineClip newTimelineClip;
    AnimationClip originAnimationClip = originTimelineClip.animationClip;
    if (!originAnimationClip.name.Contains("Recorded"))
    {
    newTimelineClip = newAnimationTrack.CreateClip(originTimelineClip.animationClip);

    }
    else
    {
    AnimationPlayableAsset originAnimationPlayableAsset = originTimelineClip.asset as AnimationPlayableAsset;

    newTimelineClip = newAnimationTrack.CreateRecordableClip(originAnimationPlayableAsset.clip.name);

    AnimationPlayableAsset newAnimationPlayableAsset = newTimelineClip.asset as AnimationPlayableAsset;
    newAnimationPlayableAsset.matchTargetFields = originAnimationPlayableAsset.matchTargetFields;
    newAnimationPlayableAsset.useTrackMatchFields = originAnimationPlayableAsset.useTrackMatchFields;

    AnimationClip animationClip = Instantiate(originTimelineClip.animationClip);
    newAnimationPlayableAsset.clip = animationClip;
    AssetDatabase.SaveAssets();
    //AnimationClip newAnimationClip = Instantiate(timelineClip.animationClip);
    //SaveFile(newAnimationTrack, newAnimationClip);
    //newTimelineClip = newAnimationTrack.CreateClip(newAnimationClip);
    //Debug.Log("Creat New:" + timelineClip.animationClip);

    }

    newTimelineClip.blendInCurveMode = originTimelineClip.blendInCurveMode;
    newTimelineClip.blendInDuration = originTimelineClip.blendInDuration;
    newTimelineClip.blendOutCurveMode = originTimelineClip.blendOutCurveMode;
    newTimelineClip.blendOutDuration = originTimelineClip.blendOutDuration;
    newTimelineClip.clipIn = originTimelineClip.clipIn;
    newTimelineClip.displayName = originTimelineClip.displayName;
    newTimelineClip.duration = originTimelineClip.duration;
    newTimelineClip.easeInDuration = originTimelineClip.easeInDuration;
    newTimelineClip.easeOutDuration = originTimelineClip.easeOutDuration;
    newTimelineClip.mixInCurve = originTimelineClip.mixInCurve;
    newTimelineClip.mixOutCurve = originTimelineClip.mixOutCurve;
    newTimelineClip.start = originTimelineClip.start;
    newTimelineClip.timeScale = originTimelineClip.timeScale;

    }
    }




    My problem is :
    1. Code above will execute success on AnimationTrack but in RecordableClip case, the clip will show "Type mismatch", and if copy new Timeline to another project, this clip will turn to "None", is there anything wrong in my code? Or is there a way to correct the "Type mismatch"?

    2. I use 2018.1.0b2 it work fine but 2017.2.1 has no CreateRecordableClip to use, is there any way to get RecordableClip in 2017 ?

    BTW: I convert RecordableClip in origin AnimationTrack to AnimationClip first.

    Thx
     
    Last edited: Jan 20, 2018
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    You need to add the animation clip to the AssetDatabase in that case. Timeline adds it as a subobject of the timeline asset.
     
  3. Suika

    Suika

    Joined:
    Nov 19, 2013
    Posts:
    33
    Thx for you reply.

    I found AddObjectToAsset to add animation clip to the timline asset, now all work fine in 2018.1.0b2,

    but 2017.2.1p2 still can't create RecordableClip , so I use CreateClip. It look well, but can't convert back to infinite clip.

    Is there any way to achieve that?

    Thx.