Using getFields to ensure all fields have been set. getValue is returning null but I cannot compare it to null

StackOverflow https://stackoverflow.com/questions/22260142

Вопрос

Here is the issue

public bool Invalid()
    {
        foreach (FieldInfo fInfo in this.GetType().GetFields())
        {
            Debug.Log(fInfo.GetValue(this))          //Log Says null
            Debug.Log(fInfo.GetValue(this) == null); //Log says false
            if (fInfo.GetValue(this) == null) return true; //so this gets skipped
        }
        return false;
    }

The objects in this class are mostly GameObject (unity). I am simply attempting to ensure that the level designer I work with knows if they missed a required GameObject from the scene or not.

Это было полезно?

Решение

My guess is:

.Log() probably accepts object and does a .ToString().. so it's possible that the an object is being returned but the .ToString() is what is returning null.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top