Set a variable to null on inspector tab
I have a Behaviour with a public var to be set on inspector:
public class TestBehaviour : MonoBehaviour
{
public string test = null;
void Update ()
{
Debug.Log ("Variable: " + test + ", is null? " + (test == null));
}
}
I want to set it to null:

But I am getting this log:
Variable: , is null? False
The variable is empty but I want it to be null How set it as null with inspector?
Answer by lloladin · Sep 14, 2016 at 03:18 PM
you can't set a string to null you need to set it to an empty string like this
Public string test = "";
i would recommend that you look up some basic C# syntax if you don't know this :)
Yes, I can set it to empty and check with an test.Length == 0 but if I really need to set as null? I can't do it via inspector? Or if I can, how to do?
I understood now, in c# I should use test = string.Empty and check with string.IsNullOrEmpty(test). Thank you
@lloladin You are not answering the author's question.
Unfortunately, you can't set a string as null in the inspector. If you leave it blank, the string is empty. [Here][1].
[1]: https://feedback.unity3d.com/suggestions/inspector-add-option-for-null-strings
Answer by clarHandsome · Feb 22, 2019 at 03:55 PM
@lloladin You're not answering the author's question.
Unfortunately, you can't initialize a string as null in the inspector. If left blank, it's initialized as string.empty ("").
Your answer
Follow this Question
Related Questions
Preprocessor conditional code for cleaner inspector options 1 Answer
Creating game objects from inspector 0 Answers
How do I bind the value of a public variable from the inspector to some other variable/constant? 0 Answers
public bool not showing in inspector 1 Answer
I have assigned it, but I get an error of Unassigned Reference Exception! 1 Answer