x


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... =)

more ▼

asked Jan 12 '10 at 04:51 PM

SisterKy gravatar image

SisterKy
2.5k 33 42 60

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Jan 12 '10 at 07:07 PM

burnumd gravatar image

burnumd
3.4k 22 35 71

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?

Jan 12 '10 at 07:33 PM SisterKy
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Jan 12 '10 at 08:10 PM

Dreamora gravatar image

Dreamora
3.3k 1 4 25

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 =)

Jan 12 '10 at 08:13 PM SisterKy
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5270
x616
x249

asked: Jan 12 '10 at 04:51 PM

Seen: 2180 times

Last Updated: Jan 13 '10 at 10:50 PM