- Home /
UnityEngine Assert IsNotNull not working on empty inspector field
public Terrain terrain;
void Start()
{
// doesn't work
Assert.IsNotNull(terrain, "My custom message.");
//works
if(Terrain == null)
Debug.LogError("bla");
}
I know about the custom == operator in Unity, as explained in this blog post, but I actually don't understand, why it affects the Assert.IsNotNull method, but not my own == check. Can anyone explain? Also, I would assume, that at least the Unity builtin Assert class would handle inspector assigned fields in a way, that I can use it for my custom error reporting. I know, that the inspector will tell me to set the field value, if I get a null reference exception, but I'd rather catch that myself, report my custom message and maybe do something else afterwards. Can I use the Assert class, am I doing something wrong or this unexpected?
Answer by Darkgaze · Jun 17, 2020 at 08:00 AM
Because Terrain with caps is not "terrain". Terrain is a class name. terrain is your variable.
Your answer
![](https://koobas.hobune.stream/wayback/20220612060342im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Check if Array.GetValue(i) is null 1 Answer
Unity c# Object reference not set to an instance of an Object ( Shooting Script ) 0 Answers
How do I fix this null problem? 1 Answer