Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question release virtual camera override immediately

Discussion in 'Timeline' started by kana1939, Mar 27, 2023.

  1. kana1939

    kana1939

    Joined:
    Jan 4, 2022
    Posts:
    6
    When the timeline stops, it does not immediately switch to a regular virtual camera, but instead waits until OnPlayableDestroy to release. Is there any way to force an immediate release of the override?

    May I know where OnPlayableDestroy is called specifically and if there is any detailed documentation available on it?
     
  2. Yuchen_Chang

    Yuchen_Chang

    Joined:
    Apr 24, 2020
    Posts:
    60
    I think
    OnPlayableDestroy
    is called from the C++ layer so I can't help you a lot on detailed informations,
    but it should be called when the PlayableGraph is destroyed (in a timeline scenario), which is when the PlayableDirector stops.
    Notice that if you set wrapmode to Hold, the PlayableDirector won't stop playing after reaching the last frame. Set it to None if you want to stop the PlayableDirector after finished playing.
    wrapmode.png
     
  3. kana1939

    kana1939

    Joined:
    Jan 4, 2022
    Posts:
    6
    Thank you, I tested it and found that `OnPlayableDestroy` is called after Update and before LateUpdate. However, I still don't know how to trigger it immediately.
     
  4. tsukimi

    tsukimi

    Joined:
    Dec 10, 2014
    Posts:
    24
    I could only give you some information, that the
    OnPlayableDestroy
    is called instantly if you directly call
    playable.Destroy()
    . So if you can find your playable, just destroy it.
    This is my test code:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3.  
    4. public class TestDestroyPlayable : MonoBehaviour
    5. {
    6.     private void Test()
    7.     {
    8.         var graph = PlayableGraph.Create();
    9.         var playable = ScriptPlayable<TestPlayableBehaviour>.Create(graph);
    10.         Debug.Log("before destroy");
    11.         playable.Destroy();
    12.         Debug.Log("after destroy");
    13.     }
    14. }
    15.  
    16. public class TestPlayableBehaviour : PlayableBehaviour
    17. {
    18.     public override void OnPlayableDestroy(Playable playable)
    19.     {
    20.         base.OnPlayableDestroy(playable);
    21.         Debug.Log("[OnPlayableDestroy] called.");
    22.     }
    23. }
    The result is:
    CalledImmediately.png

    (I've also tested PlayableGraph.Destroy(), but it will postpone the desturction of the playable, making it be called after the "after destroy" Debug.Log)
     
  5. kana1939

    kana1939

    Joined:
    Jan 4, 2022
    Posts:
    6
    Yes, that's correct. But it seems unsafe to directly call the playableGraph of the timeline since it manages itself. So, I moved the logic that needed to be handled into LateUpdate, and it worked out just as expected.
     
    Yuchen_Chang likes this.