Coroutine loading the game level does not work

I was trying to add the delay on the loading scene and by pure coincidence i found out that, the coroutine if you try to load the level it gives an error and won’t load, but works fine on the others scene
immagine
it says the level manager gameobject is inactive, but it seems fine in hierarchy like in the other scenes…
immagine

anyone knows why it happens?

It may have been inactive when the coroutine was trying to run

is possible because the main game level has some script that starts on awake, that can interfere with the active status of the level manager gameobject?

I don’t know. I don’t know what your scripts are doing and how they activate/deactivate. But the message won’t say it’s inactive if it’s not. Perhaps put a Debug.Log in the OnEnable() and OnDisable() of the script with the coroutine. Then you can see when it gets disabled

there is no much to it, Gary made us create an empty game object with this script attached…
just for show i commented the part that is correct just to rewrite the coroutine that is giving the problem

then prefab it and put it in all the 3 scenes, main menu, game level and game over screen, assigned in the relative buttons
immagine
and basically thats it, the only things that are calling the coroutines are the buttons, and all the scenes are set up in the same way

Interesting. This all looks fine but obviously the game object is disabled. Check and make sure the Level Manager is enabled before you click the button. Just to make sure. Otherwise, you could zip and upload your project somewhere and I can have a quick look at it

i found the problem… and it is very something let me tell you…When you instantiate the object into the scene, you have to grab a reference to it then. If you don’t do that, you’re probably calling on the prefab…in “on click” i dragged in the prefab, instead of dragging the gameobject directly from the hierarchy of the scene…internally screaming

Ah, yes. That will do it. Good find

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms