- Home /
Debug.Log doesn't get called when Unity freezes?
In my scene I have 2 Charas (Wasch and Lucat) walking next to each other.
By hitting space, the player can switch between the two, which ever he wants to "posses".
One script controlls the switching.
Another script takes care of the camera-movement (handled with waypoints)
The Controller-Script:
private var waschActive : boolean = false;
private var camCall = GameObject.Find("Main Camera").GetComponent("CamMove");
function Update () { if (Input.GetButtonDown("Jump")) // on Spacebar down, do: { // switch between Charas waschActive = !waschActive;
// tell the MainCam, which PC to possess
if ( waschActive )
{
Debug.Log("waschActive");
//camCall.LucatToWasch();
}
}
}
Here's the function that gets activated by the camCall.
function LucatToWasch () { Debug.Log("LucatToWasch started"); while ( !lastPointReached ) { //as long as first waypoint hasn't been reached yet, //lerp Camera towards it and make it face in the same direction while ( !firstPointReached) { Debug.Log("First Point not reached yet"); Debug.Log(transform.position); transform.position = Vector3.Lerp (camPositionLucat.position, camPathPointLucat.position, 5); Debug.Log(transform.position);
if (cameraTrans.position == camPathPointLucat.position)
{
Debug.Log("first Waypoint reached");
firstPointReached = true;
}
}
} }
Currently the camCall is commented out and if I hit space I get the "WaschActive"-Message.
(Other functionalities I implemented and left out for clarity work perfect as well)
Now the strange thing is: if I un-comment it, Unity freezes before it even prints the "WaschActive"-Message! O.o No Debug.Log-calls at all (non of the camMove-script either). No errors. The statistics-window freezes as well...
So what's happening?
Does Unity freez before it even reaches the problematic code??
Will Debug.Log not get called if it freezes.
Thanks a lot in advance!
Greetz, Ky.
~~~~~~~~~~~~~
Edit:
As burnumd said and GargerathSunman on the Forums confirmed, Unity will always hang before drawing Debug.Log!! So for infinite Loops, Debug.Log won't do...
I put in some yield; and now it doesn't crash anylonger! =D It's still weird, but sort of works... =)
Answer by burnumd · Jan 12, 2010 at 07:07 PM
What's likely happening is that those while loops are just spinning away causing Unity to freeze before it gets a chance to redraw the console. If you check the actual logs (press "Open Editor Log" in the control bar of the console before you hit play), you should see your log messages at the very end.
Never saw that EditorLog-Button! aha! =D ... I tried what you said and edited my question, though I don't think it's of any use...? But anyway thank you for your answer! =) I suspected infinity-loops at first but thought that can't be it if the Debug.Log doesn't get called. But if it's possible that it does get called, but just not drawn, that's probably it... If the cam never reaches the first PathPoint, I suppose my lerp doesn't work :-/ what am I doing wrong?
thank you so much, learning this was big help, btw if there is any person who want to find location of current log file it is at: C:\Users\AppData\Local\Unity\Editor\Editor.log
Answer by Dreamora · Jan 12, 2010 at 08:10 PM
Your camera code is a real problem.
You use while loops in there, that never use yield. That means they run at full power and prevent any other code in your project and in case of editor running the editor, from doing anything at all. Thats an infinite loop and within the editor, the editor will just forcefully kill it if it detects that
Yes! =D I put in yields, now it works... sorta, kinda, but anyway! At least something to work with =D (I knew about yield but totally misunderstood it's usage...) Thank you =)