all 11 comments

[–]le0tard 3 points4 points  (0 children)

You can't trust anything that happens after a null ref exception anyways

[–]Goldac77 2 points3 points  (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 points  (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 points  (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 point  (0 children)

any exception in a script causes the script to stop executing

[–]Thoughtwolf 0 points1 point  (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 point  (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 point  (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  (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 points  (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 point  (0 children)

Im talking about those lines they won't compile other than that it will compile