I have two logs in a foreach loop. One outputs the current element of the loop, and the other logs "1". The elements all get logged, but the "1" gets logged ones. I use Debug.Log for logging. I execute the script in a unity project. The loop looks therefore something like this
foreach(CostumeClass A in B)
{
Debug.Log("1");
Debug.Log(A);
}
The Output is
>1
>FirstElement
>SecondElement
>...
I expected
>1
>FirstElement
>1
>SecondElement
>...
CodePudding user response:
This is intentional behavior in the Unity console that can manually be toggled on or off by using the Collapse
button. When collapsing is on, the console will only display the first instance of recurring error messages, and increment a number for each recurring.
Also, unity only does this within loops. If you just write Debug.Log("!") four times, it'll appear four times... still don't really understand this.
This is because the messages are identical since they're called from the same location while in a loop, but different when you call them four times in different locations of your code.
CodePudding user response:
Apparently, Unity console packs identical logs together into one log and then writes on the right how often they appeared.