Do errors that come up in the Unity editor affect a game's performance on a device (on Android in particular)? I'm talking about errors that keep coming continuously during Update()
such as NullReferenceException
and "Debug.Log
".
|
|||||||||||||
|
Here are my tips for how to handle errors before release. Tip.1: If your game is trowing Tip.2 Wrap your Tip.3 I generally dont worry about warnings (still a good idea to fix them) and I'm 90% sure they dont effect performance. Tip.4 if you have Debug stuff in any Update() method just remove it from the build. Update() is called once per frame and you want to keep it as clean as possible. Then again with the power of today's devices a couple more if's wont do anything noticeable but is's just a good practice. |
|||||||||||||||||
|
Null Reference Exception A
While this doesn't come with a performance hit that I'm aware of, you are forcing Unity to catch the exception. In a normal application the A good approach is to use defensive programming to ensure that you get as few errors as humanly possible. It's worth pointing out that it's easy to go overboard with null checks (one early mistake a lot of people make is to put them everywhere), so keep the check to things you can't control yourself (i.e. public In our (very simple) example above, a defensive approach could be:
Or, if
Debug.Log
However, a better approach may be to use preprocessor directives to stop your Debugs from ever even being compiled into your release. This works by telling the compiler to skip over the lines of code that aren't applicable, so that your release build never has to do a check to see if it's in debug mode as it's done at compile time. |
|||||||||||||
|
These kinds of errors are exceptions which abort your functions in unintended ways. As such they can speed up or slow down the execution of your game (by skipping vital pieces of code), but the question about speed it the wrong question in this situation. Fix the code. |
|||
|