Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

Bug async load in a timeline behaviour acts very strangely

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

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    4,939
    i was having so many problems with 2 async loads sharing the same okayable track that i split it in 2
    but now it's not loading deactivated, instead it's loading active
    i trippple checked the scripts and when i use the same lines in a vanilla c# thing it works fine meaning that the scene show up as grayed out as they're loading so something's weird with timeline.
    Just to isolate that it's not one of my scene script acting out I muted those tracks and no loading happens so those tracks are the source.
    Note that i fattened the clips to make sure timeline was not going to skip these.

    upload_2021-3-17_21-15-8.png
    upload_2021-3-17_21-15-17.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.async.allowSceneActivation = false;
    31.         asyncDataPipeSo.extraData = sceneName;
    32.     }
    33. }
     
  2. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    4,939
    might be linked to this weird case
    1322501
    anyway, i'm done fighting with timeline today, seeing how long debugging timeline took, i'll probably use a home cooked FSM next time
     
  3. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    452
    For what it's worth: you're putting way too much logic in Timeline. It's meant to drive the state of things over time, not visual script your game.

    You could create a track that acts like an activation track for scenes. If a clip is active, tell a scene manager that the scene should be loaded. If not, tell the manager that your scene should be unloaded. Run the manager with a FSM.
     
  4. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    4,939
    Loading/unloading scene bits through time is visual scripting? That makes zero sense for a cinematic tool. If loading is not possible in timeline tou need to make the boundaries and limitations of timeline absolutely clear by limiting the timeline behavior access to load API or whatever else breaks with it. I read many complaints of timeline problems and it's ok, no system is perfect but pretending otherwise wastes a lot of our time.

    In this case, the thing you suggested comes from your own experience? Probably not. So do a little experiment, dogfood timeline and then we can talk on equal footing.

    I'm just seeing that Resources.Load spikes to nearly 1 second on first call when it's called by timeline, and from a FSM or vanilla c# code it's not even showing up. I was about to convert things to addressables but I'm thinking it might actually make things worse.

    So to summarize: dog food timeline, make limitations clear, lock out anything that's not working well with timeline.
     
  5. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    600
    Just to make sure I understand, are you saying that
    allowSceneActivation = false;
    is ignored and the objects in the scene are activated?
     
  6. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    4,939
    yes
     
  7. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    4,939
    this happens when it's called within the first few frames of startup, 100% repro in editor in 2020.1.17, i think it's ignoring the allowseneactivation during the first few frames, as the scene play spools up

    var asyncLoad = SceneManager.LoadSceneAsync(scene, LoadSceneMode.Additive);
    asyncLoad.allowSceneActivation = false;
    sceneAsync_DATAPIPE.async = asyncLoad;

    this happens at 0.1 seconds
    so what I end up doing is delay async load by a second.
     
unityunity