- Home /
How to check if reflected inspector field is empty
This doesn't work for some reason. In the inspector the value clearly says "none". Doesn't work for all sorts of things (Transforms, GameObjects, assets etc). I don't understand what the variable is actually referencing if it says None in the inspector?
Component c = gameObject.GetComponent<T>();
FieldInfo info = c.GetType().GetField("fieldname");
if (info.GetValue(c) == null || info.GetValue(c) == "null")
{
Debug.Log("Value is null");
}
Answer by Doeko · Sep 11, 2013 at 07:45 PM
Of course this works. Loving the way Unity editor handles null references as usual.
Component c = gameObject.GetComponent<T>();
FieldInfo info = c.GetType().GetField("fieldname");
if (info.GetValue(c) == null || info.GetValue(c).ToString() == "null")
{
5. Debug.Log("Value is null");
}
Your answer
Follow this Question
Related Questions
Get all exposed properties from all components 0 Answers
Building a Collection of Subclasses and Modifying Their Public Members from the Inspector 0 Answers
How does Unity sort fields in order of their declaration? 1 Answer
How to modify ParticleSystem from Editor script? 1 Answer
How can I hide a MonoBehaviour from the Inspector? (or make it extremely thin or compact) 1 Answer