- Home /
Debug.log firing late?
I have a huge problem here with my game crashing opun loading a scene. I'm trying to figure out how to fix it by using Debug.log but it seems that it is very late when coming to loading levels. The debug fires only when the level is LOADED not before it starts loading.
Here's my code:
if(loadingMap == true)
{
if(animated.TransitionDarkener.isPlaying == false)
{
Debug.Log("This doesnt show up untill the level already is loaded");
Global.playingMap = maps[currentMap].LoadScene;
Application.LoadLevel(maps[currentMap].LoadScene);
}
}
Is there any way to send messages to me WHILST unity is loading
It is not that it is firing late, it is that the editor GUI for the console is not updated between the Debug.Log call and the Application.LoadLevel call. The LoadLevel function freezes everything until it is done loading, so the Editor GUI is not updated until then.
Answer by Bunny83 · Oct 29, 2014 at 04:31 PM
Short answer: no. Unity (the game as well as the editor) runs in a single thread. If "something" freezes the whole application won't respond. Unity will collect all Debug.Log messages during the frame and will update the console when the frame is done.
The only solution is to roll your own logging system which runs in a sperate thread / application or to write to a logfile manually.
edit
ps: When it's freezing during a level load, you might have an infinite loop in Awake or OnEnable (maybe even Start) in one of the scripts contained in the scene you're loading.
pps: Have you checked if you actually reach that point? Does it run when you comment out the Application.LoadLevel?
To answer the pps: Yes I have.
The ps: I'll look into it :)
I found this to debug the program. I still have the bug occuring, but I can now debug my way through the code.
I'm accepting this answer, since it lead me on the way
Answer by Owen-Reynolds · Oct 29, 2014 at 04:43 PM
Make it a coroutine and toss in a yield return null
before loading the level? Yes, that is is big pain. Think I've done it twice, for ugly bugs.
Your answer
Follow this Question
Related Questions
Debug.Log Override? 3 Answers
Monodevelop 4.0.1 breakpoints won't work. 0 Answers
Debug.log not working when run from mobile 1 Answer