- Home /
very funny problems,a function doesn't excute to the end
so,the problem is this function didn't get excuted to the end,it just break at the GameObject.Find function call.and the excution flow goes to another script.so what happened?it's very funny that this function somehow breaked before it's done,the rest of the Debug.Log didn't even get excuted.i'll post another image to show the next step the excution goes to another script directly. if i comment out the code in that if scope,the rest of the code gets excuted as normal.strange? isn't it?
this function should be called when SceneManager set my game scene to be active.as you see, this is an event callback.sorry for my english,i'm not a native english speaker.so maybe we can discuss about this funny problem.what happened behind this
and there's an error below i don't quite understand 'fillTime The identifier fillTime
is not in the scope' what is this errror?
it seems i can't post that image,maybe because the limitation.
If you look into Unity's console window after running this, do you see an error. $$anonymous$$ethods do break if they encounter an unhandled exception.
The message about fillTime
is not really an error. You just have set a watch to a variable called fillTime, but the class/method you are stepping through doesn't contain such a variable.
thank you,unity didn't log any error in console window.and the extra if statement didn't get called,otherwise i would see the message to notify me it is null.i used to think in program$$anonymous$$g world method should execute to the end,no matter what.i don't know if this is unity thing,or other computer program could run the same problem.some code didn't get a chance to execute,and no error message.
Answer by clyburnw · Dec 09, 2016 at 10:50 AM
That is a giant red flag that there's an exception. I'll bet you 5 American dollars that GameObject.Find() is returning null, causing the GetComponent() call to throw. Wrap the whole thing in a try/catch and log the exception text.
you're absolutely right.you know what i found later.there's actually a problem with that GameObject.Find() call.but unity console didn't log an error. below that call i added extra check to see if 'GameCamera' is null.if it can't be found,unity should log that message.however,unity shows nothing in console.now i see that if some code or function runs into some problem,it could actually break the method execution,without any error message,and the code after the breaked point won't get executed,even though they're in the same function.if someone runs into the same strange problem,be sure to check your code carefully.there may be a potential error. and thank you for the help.
Answer by Denzil · Dec 09, 2016 at 05:07 PM
I'll bet your problem is that the "Game Camera" object is not found. Are you sure that you have an active Game Object in the scene with that name?
Do note it must be active!
If it doesn't find anything, it will return a null reference, and calling GetComponent on this null reference will will cause an exception to be thrown, which will stop execution of the script.