Search Unity

Question Why the timeline asset loaded at OnGraphStart() is been destroyed?

Discussion in 'Timeline' started by ClickOn, Mar 11, 2021.

  1. ClickOn

    ClickOn

    Joined:
    Nov 7, 2019
    Posts:
    1
    I want jump to the second tineline when the first is end. I load the second timeline asset at
    OnGraphStart() method of the lastest timeline clip in the first timeline. But when the clip start,unity show "MissingReferenceException: The object of type 'TimelineAsset' has been destroyed but you are still trying to access it." Later, I test the Sprite-Type variable and find sprite can be accessed. Someone know about this? :(
    code:
    Code (CSharp):
    1. public class TestBehaviour : PlayableBehaviour
    2.  
    3. {
    4.     private TimelineAsset testAsset;
    5.     private Sprite testImage;
    6.  
    7.     // Called when the owning graph starts playing
    8.     public override void OnGraphStart(Playable playable)
    9.     {
    10.         Debug.Log($"graph start");
    11.         Test();
    12.     }
    13.  
    14.     async void Test()
    15.     {
    16.         testAsset = (TimelineAsset)await GameEntry.Resource.LoadAssetAsync<PlayableAsset>(assetPath);
    17.         testImage = await GameEntry.Resource.LoadAssetAsync<Sprite>(spritePath);
    18.         Debug.Log($"TestAsset1:{testAsset.name}");
    19.         Debug.Log($"TestSprite1:{testImage.name}");
    20.     }
    21.  
    22.     // Called when the state of the playable is set to Play
    23.     public override void OnBehaviourPlay(Playable playable, FrameData info)
    24.     {
    25.         Debug.Log($"behaviour start");
    26.         Debug.Log($"TestAsset2:{testImage.name}");
    27.         Debug.Log($"TestSprite2:{testAsset.name}");
    28.      
    29.     }
    30. }
    Result:
    upload_2021-3-11_15-49-32.png