Skip to content

StartCoroutine with LoadSceneAsync in _Enter states loading instantly #33

Description

@st4rdog

For some reason, this code will load the level instantly on _Enter, instead of waiting until the MainMenu_Enter.

private AsyncOperation load = new AsyncOperation();

void Intro_Enter()
{
    // Preload Level
    StartCoroutine(PreLoadLevel());
}

void Intro_Update()
{
    _introTimer += Time.deltaTime;

    if (_introTimer > _introLength)
        _fsm.ChangeState(States.MainMenu);
}

void MainMenu_Enter()
{
    // Show preloaded level
    load.allowSceneActivation = true;
}

IEnumerator PreLoadLevel()
{
    load = SceneManager.LoadSceneAsync("scene", LoadSceneMode.Additive);
    load.allowSceneActivation = false;
    yield return null;
}

Moving the StartCoroutine out into the Start function will work as expected...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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