@@ -95,6 +95,11 @@ public static object GetDeclaringObject(this SerializedProperty property, Object
9595 {
9696 var treeField = members [ i ] ;
9797 reference = GetTreePathReference ( treeField , reference ) ;
98+ if ( reference == null )
99+ {
100+ continue ;
101+ }
102+
98103 if ( ignoreArrays && IsSerializableArrayType ( reference ) )
99104 {
100105 continue ;
@@ -119,8 +124,22 @@ public static object GetTreePathReference(string treeField, object treeParent)
119124 ToolboxEditorLog . LogError ( "Cannot parse array element properly." ) ;
120125 }
121126
127+ const BindingFlags flags = BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Public ;
128+
122129 var fieldType = treeParent . GetType ( ) ;
123- var fieldInfo = fieldType . GetField ( treeField , BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Public ) ;
130+ FieldInfo fieldInfo = null ;
131+ //NOTE: make sure to check in the base classes since there can be a private field/property
132+ while ( fieldType != null )
133+ {
134+ fieldInfo = fieldType . GetField ( treeField , flags ) ;
135+ if ( fieldInfo != null )
136+ {
137+ break ;
138+ }
139+
140+ fieldType = fieldType . BaseType ;
141+ }
142+
124143 if ( fieldInfo == null )
125144 {
126145 ToolboxEditorLog . LogError ( $ "Cannot find field: '{ treeField } '.") ;
@@ -421,7 +440,6 @@ public static void OverrideLabelByValue(GUIContent label, SerializedProperty pro
421440 }
422441 }
423442
424-
425443 internal static class Defaults
426444 {
427445 internal static readonly string scriptPropertyName = "m_Script" ;
@@ -472,7 +490,6 @@ public static SerializedProperty GetSize(this SerializedProperty array)
472490 return array . FindPropertyRelative ( "Array.size" ) ;
473491 }
474492
475-
476493 public static T GetAttribute < T > ( SerializedProperty property ) where T : Attribute
477494 {
478495 return GetAttribute < T > ( property , GetFieldInfo ( property , out _ ) ) ;
@@ -493,7 +510,6 @@ public static T[] GetAttributes<T>(SerializedProperty property, FieldInfo fieldI
493510 return ( T [ ] ) fieldInfo . GetCustomAttributes ( typeof ( T ) , true ) ;
494511 }
495512
496-
497513 internal static void EnsureReflectionSafeness ( SerializedProperty property )
498514 {
499515 if ( property . serializedObject . hasModifiedProperties )
0 commit comments