How can I load a scene asynchronously using addressables?

In our game we’ve built our level editor so that each level has a corresponding scene, and I’m trying to get scene addressables to work. I’ve managed to add the scenes to the Default Local Group but when I try to load the scene asset, it fails. Here is the code I’ve written to try and load the scene asset:

# sceneAsset is an AssetReference
sceneAsset.LoadAsset<SceneAsset>().Completed += operation => { Debug.Log($"Loaded Scene: {operation.Result} in async operation {operation}"); };

This will log out this text when run:

Loaded Scene: in async operation UnityEngine.ResourceManagement.ChainOperation`2[UnityEditor.SceneAsset,System.Boolean] result = , status = Failed, Valid = True, canRelease = False

Any help in this manner would be greatly appreciated!

1 Like

Ah, of course shortly after posting this thread I discovered how to do it myself. Here is the code for anyone interested:

Addressables.LoadScene(sceneAsset, LoadSceneMode.Additive);
3 Likes

How to show the progress like the progress showing on UI in code below:

private void OnLoadDone(IAsyncOperation<GameObject> async)
    {
        if (async.Status == AsyncOperationStatus.Failed)
        {
            Debug.LogException(async.OperationException);
            report.text = "Failed to instantiate";
        }

        else
        {
            report.text = string.Format("Loading: {0}%", async.PercentComplete);

            if (async.Status == AsyncOperationStatus.Succeeded)
            {
                report.text = "Successfully loaded";
                myPlayerObject = async.Result;
                button2.SetActive(true);
            }
        }
    }

    public void DownloadModel()
    {
        myPlayer.LoadAsset<GameObject>().Completed += OnLoadDone;
    }
1 Like

@roshaantariq use var op = myPlayer.LoadAsset();op.Completed +=onLoadDone;
And e.g. in a coroutine while the async operation has not completed;
Debug.Log(op.percentComplete);