Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Timeline is changed when replace animationClip on runtime

Discussion in 'Timeline' started by litefeel, May 5, 2019.

  1. litefeel

    litefeel

    Joined:
    Dec 6, 2016
    Posts:
    45
    Hi.

    I am using timeline to make the story, I need to change the animation clip at runtime, but when I play it once at runtime, and then save it, the timeline asset is modified.

    How to reproduce?
    1. download the demo
    2. Open SampleScene.unity
    3. Play it
    4. Stop it
    5. Ctrl + S to save it.
    6. now. the timeline asset was modified.


    What did I do at runtime?
    like this https://forum.unity.com/threads/change-animationtrack-clip-at-runtime.545671/#post-3600296
    1. Change the clip(s)
    2. Play the playable director
    3. Change it back.


    this is demo at github https://github.com/litefeel/TimelineReplaceClip
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,068
    Changes to a timeline asset in PlayMode don't get reverted when going back to EditMode, because it's an asset. Only the scene gets reverted.
     
  3. litefeel

    litefeel

    Joined:
    Dec 6, 2016
    Posts:
    45
    Thanks for your reponse.
    Code (CSharp):
    1.  
    2. private void DoPlay()
    3. {
    4.     var director = GameObject.Instantiate(prefab);
    5.     var map = new Dictionary<AnimationPlayableAsset, AnimationClip>();
    6.     ReplaceUtil.ReplaceAll(director, clip, map);
    7.     director.Play();
    8.     ReplaceUtil.RestoreAsset(map); // Restore the timeline
    9.     director.stopped += (obj) =>
    10.     {
    11.         GameObject.Destroy(obj.gameObject);
    12.     };
    13. }
    14.  
    I restore the timeline asset.
    The animation clip has not been modified, but the cinemachine clip has been modified.
    I have not modified cinemachine in the code.


    Please run the demo, then stop and save the scene.
    You can see that the timeline asset has been modified.
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,068
    In the ReplaceUtil, you are modifying AnimationPlayableAssets. These are (hidden) subassets of the timeline asset, so I strongly suspect that modifying them is what is causing it.

    Running the sample I see the file is being written, but there are no actual content changes. Which may be expected behavior, because the asset has changed twice.
     
  5. litefeel

    litefeel

    Joined:
    Dec 6, 2016
    Posts:
    45
    Hi.
    Must be done this way to reproduce:
    1. Play it
    2. Stop it
    3. Ctrl + S to save it. (important!!!)
    4. now. the timeline asset was modified.

    upload_2019-5-9_22-7-28.png
    This is the modified file.

    Interestingly,
    The ciememachine that was not changed in the code was modified, the animation not been modified.

    So, how to don't modify ciememachine.
    Please help me.
     
  6. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,068
    Ok, once that change is made it doesn't change after that though, does it? It's a bug in the default values of the clip, but the data that's being saved is not actually used.
     
  7. litefeel

    litefeel

    Joined:
    Dec 6, 2016
    Posts:
    45
    Is this a bug in ciememachine?
    Can you fix it?
     
  8. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,068
    It's a timeline bug. Yes, we can fix it. Also, I think you can workaround it by accessing the mixInCurve and mixOutCurve properties on the timelineClips via script before saving . That will assign them their proper defaults, and prevent the value from being randomly introduced.

    The timeline may still be flagged as dirty after, but saving should cause no visible difference.