Parent is not active...but there is no parent!
I have sort of a complicated question, and I'm not quite sure how to word myself... So please bear with me.
So I have a scene that instantiates a GameObject with a script on it, that sorta kicks off the whole thing. This GameObject, named GameManager, is not destroyed upon loading new scenes using DontDestroyOnLoad(gameObject);
. So the first thing my GameManager script does, is to play a little hard-coded "intro animation", and then loads the main menu of my game. The "animation" plays as a float timer
decreases in the Update()
function like this:
if(timer > 0)
{
timer -= Time.deltaTime;
return;
}
else if(timer <= 0 && loading)
{
changeLevel(nextLevel);
return;
}
As you can see, once timer
is 0, a function changeLevel(nextLevel)
is called. nextLevel
is simply and int that says which level to load. loading
is a bool that is set false in the changeLevel()
function to prevent it from being called every frame.
In the main menu, there's a Canvas that holds all the GUI-elements, and this canvas has a script, MainMenu.cs. In this script I have made a variable for the GameManager script named gm
, so that I can access public variables and functions. And so when I press play in the main menu, I try calling a function in the GameManager script called splash()
like this: gm.splash()
, as well as setting gm.nextLevel = 2
to let it know what level to load next. The splash()
function simply instantiates a Canvas, and sets my float timer
to 3 in the GameManager script, so that it should take 3 seconds before loading the next level.
Now here comes my question. The Update()
function in my GameManager script does not seem to be called every frame, like it should. I was doing some digging and I tried checking whether the object was active or not using gm.gameObject.activeSelf
in the MainMenu script, and it is. But it seems the parent is not active, which I checked with gm.gameObject.activeInHierarchy
from the MainMenu script. Thing is, my GameManager object does not have a parent, it's just there in the hierarchy all by itself. And since it's not destroyed upon loading new scenes, it should still be active, no?
Sorry for the long question, but I felt it necessary to give the whole backstory to my situation for you guys to sorta understand my question... Thanks for taking the time to look at my problem! :)
After a little bit of processing, I've come to the conclusion that it makes sense for the "parent" of my Game$$anonymous$$anager object not to be active, as it doesn't exist... If it's null, then I assume it's also inactive.
This doesn't resolve my problem though, as to why the Update()
function isn't running each frame, so I'm not going to delete my initial question.
I might add that I tried to use a Coroutine to achieve the wait of 3 seconds before loading the next scene, but then I get an error saying Coroutine couldn't be started because the game object 'Game$$anonymous$$anager' is inactive!
, so that leaves me pretty much at the same spot.