Search Unity

Debug.Log in loop hangs unity3d

Discussion in 'Scripting' started by dansav, Feb 23, 2010.

  1. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    I have many routines that output to Debug.Log. They are all in order. First function 1 runs, then 2 all the while outputing to the console the information about the functions. IF I just run function 1 and 2 I get output to the console.

    But for some reason if I run function 3 which has a long loop, all the Debug.Log's are not written to the console, as if they can't be written while a loop is going on. So I can't debug the loop.

    So what's happening is it stored in a buffer which is not released during a long loop?

    If I make the loop smaller it works fine. But as it gets larger it totally hangs up unity3d. If I take out the Debug.Log calls it also runs fine.

    ???

    Dan
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    I think the Debug.Log calls are buffered until the end of the frame update. A tight loop will be delayed by the calls, but they won't be displayed until the end of the frame.
     
  3. andrea85cs

    andrea85cs

    Joined:
    Feb 10, 2009
    Posts:
    11
    If you want utilized a long loop function, you should use a Coroutine function.
    For Example :
    Code (csharp):
    1.  
    2. ....
    3. StartCoroutine(Function3());
    4. ....
    5.  
    6. IEnumerator Function3() {
    7.   while (true) {
    8.    .....
    9.    Debug.Log("1 CheckPoint");
    10.    yield return new WaitForEndOfFrame();
    11.    .....
    12.    Debug.Log("2 CheckPoint");
    13.    yield return new WaitForEndOfFrame();
    14.   }
    15. }
    16.