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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug playable behavior scene loading async only working in a build not editor play

Discussion in 'Timeline' started by laurentlavigne, Jan 4, 2021.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,000
    where the loading is done with this

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3. using UnityEngine.SceneManagement;
    4.  
    5. public class TimelineSceneLoadAsync : PlayableAsset
    6. {
    7.     public SceneReference sceneName;
    8.     public AsyncDataPipe asyncDataPipe;
    9.  
    10.     public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
    11.     {
    12.         var playable = ScriptPlayable<TimelineSceneLoadAsyncBehaviour>.Create(graph);
    13.         var sceneLoadBehaviour = playable.GetBehaviour();
    14.         sceneLoadBehaviour.sceneName = sceneName;
    15.         sceneLoadBehaviour.asyncDataPipe = asyncDataPipe;
    16.         return playable;
    17.     }
    18. }
    19. public class TimelineSceneLoadAsyncBehaviour : PlayableBehaviour
    20. {
    21.     public string sceneName = "";
    22.     public AsyncDataPipe asyncDataPipe;
    23.  
    24.     public override void OnBehaviourPlay(Playable playable, FrameData info)
    25.     {
    26.         if (asyncDataPipe.async == null)
    27.             asyncDataPipe.async= SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
    28.         asyncDataPipe.async.allowSceneActivation = false;
    29.     }
    30. }

    and scene activation is done with that

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3.  
    4. public class TimelineSceneActivate : PlayableAsset
    5. {
    6.     public AsyncDataPipe asyncDataPipe;
    7.  
    8.     public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
    9.     {
    10.         var playable = ScriptPlayable<TimelineSceneActivateBehaviour>.Create(graph);
    11.         var sceneActivateBehaviour = playable.GetBehaviour();
    12.         sceneActivateBehaviour.asyncDataPipe = asyncDataPipe;
    13.         return playable;
    14.     }
    15. }
    16. public class TimelineSceneActivateBehaviour : PlayableBehaviour
    17. {
    18.     public AsyncDataPipe asyncDataPipe;
    19.  
    20.     public override void OnBehaviourPlay(Playable playable, FrameData info)
    21.     {
    22.         if (asyncDataPipe.async != null)
    23.             asyncDataPipe.async.allowSceneActivation = true;
    24.     }
    25. }

    using a data pipe (aka channel) SO to store the async operation
    both loading and activation are on the same playable track like so
    upload_2021-1-4_14-35-40.png

    in a build it works fine and by the time activation is reached (the second block) the async load has finished
    but in editor this never loads the scene