Check if null Unity code example
Example: check c# unity inspector field not null
public static bool IsNull<T>(this T myObject, string message = "") where T : class
{
if (myObject is UnityEngine.Object obj)
{
if (!obj)
{
Debug.LogError("The object is null! " + message);
return false;
}
}
else
{
if (myObject == null)
{
Debug.LogError("The object is null! " + message);
return false;
}
}
return true;
}