tiny_foundry_man
tiny_foundry_man

Reputation: 1

Coroutine does not start in between scenes

I have a main menu scene with the code

void Start()
{
    StartCoroutine (FadeIn());
}

IEnumerator FadeIn()
{
    whiteFadeInAnim.Play("whiteEntryMenu");
    yield return new WaitUntil(()=>whiteFadeIn.color.a==0);
    ShowMainMenu();
    Debug.Log ("Coroutine started");
}

whiteFadeInAnim.Play("whiteEntryMenu"); gradually reduces the alpha of a white sprite gameobject. Then, ShowMainMenu() shows the menu buttons with some animations. The scene works fine when I play it. However, when I try to load this scene from another scene using - SceneManager.LoadScene("menu");, nothing happens. The menu scene is loaded but all I can see is the white sprite and the debug log does not appear. There are no errors shown either. Why is this happening?

Upvotes: 0

Views: 63

Answers (1)

yuri206
yuri206

Reputation: 79

As I cannot comment on your question, I'll post this as an answer.

First of all check if your script and the GameObject it is on, are active in the scene after it is loaded.(Blue ticks at the name of the GameObject and the script)

You also may want to try some other method than Start(), for example OnEnable() may give you the same output, as the script will be enabled at the scene start (if it is saved as an enabled script), but with that you can also reuse your script without having to reload the scene. (as it would be with Start())

Also you may want to read this to figure out any problems with the order in which the MonoBehaviour methods are executed.

Upvotes: 1

Related Questions