Skip to content

Loading progress logical error #1

@Dandarawy

Description

@Dandarawy

Thanks guys for the great tutorial, there are some logical issues in the LoadingScreen function. Although this function is not used in the final version of the tutorial it's highly possible someone may take it as a reference, so I hope you can fix it.

To understand the problem I recommend to add some Debug messages in the function as the following:

    IEnumerator LoadingScreen()
{
    float totalProgress = 0;
    //Iterate through all the scenes to load
    for (int i = 0; i < scenesToLoad.Count; ++i)
    {
        Debug.Log("check loading of scene " + i + " :" + scenesToLoad[i].isDone);
        while (!scenesToLoad[i].isDone)
        {
            //Adding the scene progress to the total progress
            totalProgress += scenesToLoad[i].progress;
            //the fillAmount needs a value between 0 and 1, so we devide the progress by the number of scenes to load
           Debug.Log($"{i}=>total progress/count={totalProgress}/{scenesToLoad.Count}");
            yield return null;
        } 
    }
    Debug.Log($"End of LoadingScreen coroutine!");
}

Issues:

  1. The Idea of iterating over all scenes using for loop with this way is not the right way to do it, as all scenes will be loaded in parallel and the while loop will keep looping until the first scene get completely loaded and in the same time other scenes will get some progress as well which will not be counted in the totalProgress

  2. In one iteration of the for loop, while loop will keep looping many times and it will add the progress of the same scene over and over again, so the previous debug code will debug something like:
    0=>total progress/count=0.9/2
    0=>total progress/count=1.8/2
    0=>total progress/count=2.7/2

  3. The value of the AsyncOperation.progress ranges from 0 to 0.9 not from 0 to 1, this is something that should be considered as well

  4. Because you're loading the Gameplay scene in a single mode not additive, once the scene get loaded the mainMenu scene will get unloaded and the for loop function will stop at i=0 and will never go to the next iteration, so with the previous debugs you will get this message only
    check loading of scene 0 :False
    and will never get
    check loading of scene 1 :False

I hope you guys take those points in consideration and write a cleaner version of LoadingScreen function so the people can follow it in their games.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions