- Home /
Do debug.log messages show up in unity console in exactly the sequence those statements are called?
Hi. Ive been trying to debug my code, and one thing that seems to boggle my mind is that debug.log statements seem to be appearing out of order.
I have a recursive function that calls the same function in its neighboring object, which also calls the same function in its own neighboring object and so on. The sequence I am expecting is: (assuming all recursive functions in unity happen in single thread, or am I wrong in that assumption?)
"function called" - (in object 1) "
function called" - (in object 2)
"function half way done" - (in object 2)
"function ending" - (in object 2)
"function half way done" - (in object 1)
"function ending" - (in object 1).
--
Whats happening instead is:
"function called" - (in object 1)
"function half way done" - (in object 1)
"function ending"-(in object 1)
"function called" - (in object 2)
"function half way done" - (in object 2)
"function ending"-(in object 2)
So I am really wondering is that really the sequence in which code is getting executed? or is it just debug.log printing it asynchronously or something?
Also can anyone confirm if I call a function inside object 2 from object 1, will that function execute in same thread or will the new function be executed in a separate thread? this is sort of crucial to my game logic that control flow happens as it would in a single thread.
How can we help debug your code if you don't provide it??
Yes, Unity is single-threaded. You can manipulate your own thread but no (or very, very few) methods of the Unity API can be called from the other thread.
Are you sure you haven't checked the Collapse button in the console tab?