Esa
Esa

Reputation: 1666

Application.Load is not immediate

I have two functions:

private void Function1()
{
    Function2();
    // Do other stuff here which gets executed

}

private void Function2()
{
    Application.LoadLevel("Level");
}

I had always lived in the thought that calling Application.LoadLevel() is immediate, but instead the other stuff in the Function1 does get executed.

Has this been changed in recent versions or has it always been there?

Upvotes: 0

Views: 213

Answers (2)

sandygk
sandygk

Reputation: 56

You could use coroutines to achieve that effect.

private void Function1()
{
    StarCoroutine(Coroutine1());
}

private void Function2()
{
    Application.LoadLevel("Level");
}

private IEnumerator Coroutine1()
{
    Function2();

    yield return null;

    // Do other stuff here which gets executed
}

Upvotes: 1

Radu Diță
Radu Diță

Reputation: 14171

Application.LoadLevel is immediate in the sense that frames aren't generated until the level is loaded, but the current frame still ends.

This means that code register to execute will get executed.

It won't stop the current method from ending.

Upvotes: 1

Related Questions