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 which variable saves the loading progress of webgl?

Discussion in 'WebGL' started by uziiii2612195, Nov 16, 2021.

  1. uziiii2612195

    uziiii2612195

    Joined:
    Sep 26, 2021
    Posts:
    8
    upload_2021-11-16_17-34-5.png
    for example the program is loading 90%. how do i get that 90% in a variable .help
     
  2. MarcelPursche

    MarcelPursche

    Unity Technologies

    Joined:
    Mar 3, 2021
    Posts:
    44
    Hi,
    You can access the loading progress using the progress callback given to the UnityLoader in Javascript.
    You can create a custom template to modify the "index.html" to hook into that callback https://docs.unity3d.com/Manual/webgl-templates.html

    Code (JavaScript):
    1. createUnityInstance(canvas, config, (progress) => {
    2.      // Do something with progress variable here
    3.      // progress is within range [0,1]
    4.      progressBarFull.style.width = 100 * progress + "%";   }).then((unityInstance) => {
    5.       loadingBar.style.display = "none";
    6. }).catch((message) => {
    7.       alert(message);
    8. });