Reflection not working in Unity base classes?

I’m trying to get a private static field of the ButtonEditor Unity class using reflection, but apparently it’s failing because the FieldInfo object returned is null.

        var showNavigation = typeof(ButtonEditor).GetField("s_ShowNavigation", BindingFlags.NonPublic | BindingFlags.Static);
        Debug.Log(showNavigation != null); // Prints false

I tried doing the same thing but on a private static field on a class that I derived from ButtonEditor and it works properly.
How do I make this work?

Because the ButtonEditor class does not have such a field. However its base class SelectableEditor does have that static field.

Static members are not really derived or inherited since they belong to the class. Inheritance is about instances.

1 Like