Search Unity

Question timeline and loadsceneasync hiccup

Discussion in 'Timeline' started by laurentlavigne, Mar 17, 2021.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,335
    loadsceneasync causes a hiccup, this hiccup throws the timeline out of sync with audio, the timeline is set to DSP clock, what's the solution?
     
  2. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Please file a bug with your use case.

    I've got a potential fix for that, but I've been looking for a repro to test against
     
    laurentlavigne likes this.
  3. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,335
    alright I filled that bug
    here is the repro data in picture
    upload_2021-3-16_22-6-52.png
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3. using UnityEngine.SceneManagement;
    4.  
    5. public class TimelineSceneLoadAsync : PlayableAsset
    6. {
    7.     #if UNITY_EDITOR
    8.     [Multiline] public string comment;
    9.     #endif
    10.     public SceneReference sceneName;
    11.     public AsyncDataPipe_SO asyncDataPipeSo;
    12.  
    13.     public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
    14.     {
    15.         var playable = ScriptPlayable<TimelineSceneLoadAsyncBehaviour>.Create(graph);
    16.         var sceneLoadBehaviour = playable.GetBehaviour();
    17.         sceneLoadBehaviour.sceneName = sceneName;
    18.         sceneLoadBehaviour.asyncDataPipeSo = asyncDataPipeSo;
    19.         return playable;
    20.     }
    21. }
    22. public class TimelineSceneLoadAsyncBehaviour : PlayableBehaviour
    23. {
    24.     public string sceneName = "";
    25.     public AsyncDataPipe_SO asyncDataPipeSo;
    26.  
    27.     public override void OnBehaviourPlay(Playable playable, FrameData info)
    28.     {
    29.         asyncDataPipeSo.async = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
    30.         asyncDataPipeSo.extraData = sceneName;
    31.         asyncDataPipeSo.async.allowSceneActivation = false;
    32.     }
    33. }
    also of note: activating hiccups a lot more than normal

    activation script

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3. using UnityEngine.SceneManagement;
    4.  
    5. public class TimelineSceneActivate : PlayableAsset
    6. {
    7.     #if UNITY_EDITOR
    8.     [Multiline] public string comment;
    9.     #endif
    10.     public AsyncDataPipe_SO asyncDataPipeSo;
    11.     public bool setSceneActive;
    12.     public SceneReference sceneToUnload;
    13.  
    14.     public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
    15.     {
    16.         var playable = ScriptPlayable<TimelineSceneActivateBehaviour>.Create(graph);
    17.         var sceneActivateBehaviour = playable.GetBehaviour();
    18.         sceneActivateBehaviour.asyncDataPipeSo = asyncDataPipeSo;
    19.         sceneActivateBehaviour.setSceneActive = setSceneActive;
    20.         sceneActivateBehaviour.sceneToUnload = sceneToUnload;
    21.         return playable;
    22.     }
    23. }
    24. public class TimelineSceneActivateBehaviour : PlayableBehaviour
    25. {
    26.     public AsyncDataPipe_SO asyncDataPipeSo;
    27.     public bool setSceneActive;
    28.     public SceneReference sceneToUnload;
    29.     public override void OnBehaviourPlay(Playable playable, FrameData info)
    30.     {
    31.         if (asyncDataPipeSo.async != null)
    32.             asyncDataPipeSo.async.allowSceneActivation = true;
    33.         asyncDataPipeSo.async = null;
    34.         if (setSceneActive)
    35.             SceneManager.SetActiveScene(SceneManager.GetSceneByPath(asyncDataPipeSo.extraData));
    36.         //unloading
    37.         if (!string.IsNullOrEmpty(sceneToUnload.ScenePath))
    38.             SceneManager.UnloadSceneAsync(sceneToUnload);
    39.     }
    40. }

    async datapipe:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [CreateAssetMenu(menuName = "SO/Async (data pipe)")]
    4. public class AsyncDataPipe_SO : ScriptableObject
    5. {
    6.     public AsyncOperation async;
    7.     public string extraData;
    8. }
     
  4. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,335
    bug # 1322234