What are some of the error checking that you scripting gurus build into your code?
I’m attempting to do some basic error checking like verifying that an object exists, or if there’s even anything in the input field for a variable. What are some ways of doing this?
What are some of the other types error checking you do?
Renderer r = transform.GetComponent<Renderer>();
if (r ! = null) // <- this is a null check
{
r.enabled = false;
}
There are basically two approaches, you can be liberal with null checks which will make your game more robust and less likely to crash. On the other hand you can do nothing, or throw your own exceptions which is more inline with a Fail Fast philosophy. I reccomend a combination of both. if you null check everywhere then more bugs will slip through and they will be harder to find. If you are too liberal with exceptions you’ll waste extra time on small things which aren’t important to the core game.