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. Dismiss Notice

Question WebGL build crashes when Addressables.DownloadDependenciesAsync reaches completion?

Discussion in 'Addressables' started by badplastics, Jul 27, 2021.

  1. badplastics

    badplastics

    Joined:
    Jul 4, 2018
    Posts:
    4
    Hey all! I'm brand new to Addressables and I've been fighting with this WebGL build for a while — hoping somebody here might be able to help me out! Edit: Using Unity 2021.1.15f1 and Addressables 1.16.19.

    The following script is set up on a start menu scene that preloads the main scene of the project ("SurfersRest") using Addressables. The function StartGame() is connected to a UI button's OnClick() listener. Everything seems as though it's working as expected until handle.GetDownloadStatus().Percent presumably reaches 1.0f, at which point the page crashes and Google Chrome throws an Error Code 5. I've cleared my browser cache, cleaned and rebuilt my addressables, tried variations of the conditional handle.Status == AsyncOperationStatus.Succeeded (e.g. handle.GetDownloadStatus().Percent == 1.0f) and still can't figure out what I'm doing wrong, and the documentation has me feeling slightly out of my depth. Any and all advice greatly appreciated!

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. using UnityEngine.SceneManagement;
    5. using UnityEngine.ResourceManagement.AsyncOperations;
    6. using UnityEngine.ResourceManagement.ResourceProviders;
    7. using UnityEngine.AddressableAssets;
    8.  
    9. public class GameManager : MonoBehaviour
    10. {
    11.     public Button button;
    12.     public Text buttonText;
    13.     public AsyncOperationHandle handle;
    14.  
    15.     public void Start()
    16.     {
    17.         button.interactable = false;
    18.         StartCoroutine(LoadMainSceneAsync());
    19.     }
    20.  
    21.     public IEnumerator LoadMainSceneAsync()
    22.     {
    23.         handle = Addressables.DownloadDependenciesAsync("SurfersRest", false);
    24.         yield return handle;
    25.  
    26.         if (handle.Status == AsyncOperationStatus.Succeeded)
    27.         {
    28.             buttonText.text = "Start Game";
    29.             button.interactable = true;
    30.         }
    31.     }
    32.  
    33.     public void Update()
    34.     {
    35.         if (!handle.IsDone)
    36.         {
    37.             buttonText.text = "Loading… (" + Mathf.Floor(handle.GetDownloadStatus().Percent * 100) + "%)";
    38.         }
    39.     }
    40.  
    41.     public void StartGame()
    42.     {
    43.         button.interactable = false;
    44.         buttonText.text = "Initializing…";
    45.         Addressables.LoadSceneAsync("SurfersRest", LoadSceneMode.Single, true);
    46.         Addressables.Release(handle);
    47.     }
    48. }
    The code works as expected in the Editor with "Use Existing Build," it's only giving me problems when I try running an actual WebGL build.
     
    Last edited: Jul 30, 2021
  2. badplastics

    badplastics

    Joined:
    Jul 4, 2018
    Posts:
    4
    Update on this: Chrome continues to be crashing while Firefox, and even Safari with experimental WebGL2 support, don't have an issue beyond a lengthy hang between the load completing and the button becoming interactable (via the conditional in the coroutine).

    At first I thought this might be a code stripping issue as some people have found with Addressables, but now I'm thinking it's actually Chrome panicking about the sudden rapid increase in RAM usage for the WebGL build — the Addressables scene and its dependencies are ~140MB. Has anyone had this issue, and does anyone know of a workaround?
     
  3. inwind

    inwind

    Joined:
    Apr 23, 2021
    Posts:
    1
    I had a same issue till unchecked the Use Asset Bundle Cache. Try it. I think it need future deep analsys.
     
    badplastics likes this.