Search Unity

Download assets on App Launch

Discussion in 'Addressables' started by daganunity, Feb 18, 2019.

  1. daganunity

    daganunity

    Joined:
    Sep 16, 2015
    Posts:
    2
    Hello,
    I am using the Addressables 0.5.3-preview package with Unity 2018.2.15f1.

    I'm trying to download all my assets (which are scenes) from remote load path, to memory, on the app first launch without actually loading the scenes.

    I tried to use DownloadDependencies (below) but apparently its start downloading, and automatically releasing the scenes- so actually the scenes are not loaded to memory. That means that the next call to Addressables.LoadScene will download the asset instead of loading it locally.
    Code (CSharp):
    1. Addressables.DownloadDependencies(sceneName);

    The second thing I tried is LoadAsset:
    Code (CSharp):
    1. Addressables.LoadAsset<SceneAsset>(SceneName).Completed += onLoadDone;
    2.  
    3. private void onLoadDone(IAsyncOperation<SceneAsset> obj)
    4. {
    5.     if (obj.Status == AsyncOperationStatus.Succeeded)
    6.     {
    7.         Debug.Log(obj.Result);;
    8.     }
    9.     else
    10.     {
    11.         Debug.LogError("Failed to load scene at address");
    12.     }
    13. }
    Now I'm getting the below error in play mode and in build process (However- if I ignore this error in the player- all scenes are being loaded into memory as expected).

    Could anyone help me how should I just download all scenes assets into memory for future use?

    Thanks,
    Roei
     
    Last edited: Feb 18, 2019
  2. tswierkot

    tswierkot

    Joined:
    Feb 15, 2017
    Posts:
    25
    DownloadDependencies works as it should - it makes sure the needed assets are on disk before you need them.

    Scenes are loaded in memory when they are being used. AFAIK you can't just load them into memory. SceneAsset objects also belong in the UnityEditor namespace - the game won't build if you use them in non-editor scripts.

    If you really want to preload all your scenes into memory, then load those scenes (Adressables.LoadScene) at game start and after loading disable all the root GameObjects in them until you need them.