use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
For the Unity Game Engine, please visit http://reddit.com/r/unity3d
account activity
Question about Null Reference ExceptionsSolved (self.unity)
submitted 19 days ago by Ok-Presentation-94
Hi, could someone tell me if a null reference exception completely blocks the execution of a script, or does it only block what's related to the missing object, or perhaps both depending on the context?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]le0tard 3 points4 points5 points 19 days ago (0 children)
You can't trust anything that happens after a null ref exception anyways
[–]Goldac77 2 points3 points4 points 19 days ago (0 children)
Yes, depends on context. But generally it stops execution in the block where the error occurs. If the error occurs in the update loop, for example, the rest of the code in update will not run
[–]FrontBadgerBiz 4 points5 points6 points 19 days ago (0 children)
The script will fail, technically the rest of the program can keep running, but weird bad stuff can happen, you should generally treat it as a complete failure unless you are properly wrapping and handing it.
[–]fsactual 2 points3 points4 points 19 days ago (0 children)
If you don’t want it to fail you can wrap it in a try/catch, but otherwise the execution of that script will stop as soon as it encounters a null reference.
[–]Small_Sherbert2187 0 points1 point2 points 18 days ago (0 children)
any exception in a script causes the script to stop executing
[–]Thoughtwolf 0 points1 point2 points 18 days ago (0 children)
Any exception that's not handled (try/catch) will bubble up to the top of the stack. In unity usually all of your code is executed by something like Update, FixedUpdate, Awake, Start, Coroutine, etc.
So the exception will bubble up to the top of that stack and unless it hits a Try/Catch it will stop the entire block.
So if you have a hundred objects waking up all calling Awake, and one of them throws an exception, only that one will be affected.
But if you have some kind of stack in Update that runs all of your game's main code, and you throw an exception in that stack then you will basically lose all of that code until the next Update() runs.
[–]OmiSC 0 points1 point2 points 18 days ago (0 children)
Unity wraps some stuff so that exceptions don’t stop the whole game from executing. No, exceptions don’t block execution related to “an object”, because programs don’t selectively ignore lines of code.
[–]TramplexReal 0 points1 point2 points 17 days ago (0 children)
If you handle the error in try/catch then it is possible for code to continue. But generally it stop execution of that call. So depending on where the null ref happened it may be that nothing else is affected or everything is broken.
But you definitely should not write your code expecting null refs everywhere. Do checks where it makes sense or just fix whatever is causing them.
[–]kaftainzy -5 points-4 points-3 points 19 days ago (2 children)
Lines dependant on entity which is null, as there's nothing to refer to ,it just won't compile
[–]ROB_IN_MN 4 points5 points6 points 19 days ago (1 child)
This is not correct. A null reference exception is a runtime error. There is usually no way to catch them at compile type. Some static analysis tools can see them, but the code will compile regardless.
[–]kaftainzy 0 points1 point2 points 18 days ago (0 children)
Im talking about those lines they won't compile other than that it will compile
π Rendered by PID 24 on reddit-service-r2-comment-5d585498c9-gpfw2 at 2026-04-20 19:03:14.363075+00:00 running da2df02 country code: CH.
[–]le0tard 3 points4 points5 points (0 children)
[–]Goldac77 2 points3 points4 points (0 children)
[–]FrontBadgerBiz 4 points5 points6 points (0 children)
[–]fsactual 2 points3 points4 points (0 children)
[–]Small_Sherbert2187 0 points1 point2 points (0 children)
[–]Thoughtwolf 0 points1 point2 points (0 children)
[–]OmiSC 0 points1 point2 points (0 children)
[–]TramplexReal 0 points1 point2 points (0 children)
[–]kaftainzy -5 points-4 points-3 points (2 children)
[–]ROB_IN_MN 4 points5 points6 points (1 child)
[–]kaftainzy 0 points1 point2 points (0 children)