x


How to call Debug.Log() only once when you run game

Hello everyone I have a very simple question about Debug.Log(). how can I get Unitys console to only show the variable once instead of the log looping. I want to use a non static variable if possible.

more ▼

asked Feb 25 '10 at 01:59 AM

Ben 3 gravatar image

Ben 3
1 1 1 1

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

2 answers: sort voted first

place it in Start() or Awake() function instead of Update. So you get something like:

var mySpecialVar;

function Start() {
    Debug.Log("Only once i want to show you my: " + mySpecialVar);
}
more ▼

answered Feb 25 '10 at 02:04 AM

Jaap Kreijkamp gravatar image

Jaap Kreijkamp
6.4k 20 26 70

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

If you have to call it in function Update, if you can call it in the first frame, you could do something like

var debugged : boolean = false;

function Update ()
{
   if (!debugged)
   {
     Debug.Log("My Debug Output");
     debugged = true;
   }
}

(This would have the additional merit that you could just set debugged = true when you're finally building the thing, as Debug can be a performance-drag)

If you need it in a later frame, after some event, you'd have to fiddle a bit with where you set the debugged-variable, but basically this should do the trick...?

Greetz, Ky.

more ▼

answered Feb 25 '10 at 04:56 AM

SisterKy gravatar image

SisterKy
2.4k 33 41 59

(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:

x294
x239

asked: Feb 25 '10 at 01:59 AM

Seen: 1575 times

Last Updated: Feb 25 '10 at 01:59 AM