@@ -95,6 +95,11 @@ public static object GetDeclaringObject(this SerializedProperty property, Object
95
95
{
96
96
var treeField = members [ i ] ;
97
97
reference = GetTreePathReference ( treeField , reference ) ;
98
+ if ( reference == null )
99
+ {
100
+ continue ;
101
+ }
102
+
98
103
if ( ignoreArrays && IsSerializableArrayType ( reference ) )
99
104
{
100
105
continue ;
@@ -119,8 +124,22 @@ public static object GetTreePathReference(string treeField, object treeParent)
119
124
ToolboxEditorLog . LogError ( "Cannot parse array element properly." ) ;
120
125
}
121
126
127
+ const BindingFlags flags = BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Public ;
128
+
122
129
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
+
124
143
if ( fieldInfo == null )
125
144
{
126
145
ToolboxEditorLog . LogError ( $ "Cannot find field: '{ treeField } '.") ;
@@ -421,7 +440,6 @@ public static void OverrideLabelByValue(GUIContent label, SerializedProperty pro
421
440
}
422
441
}
423
442
424
-
425
443
internal static class Defaults
426
444
{
427
445
internal static readonly string scriptPropertyName = "m_Script" ;
@@ -472,7 +490,6 @@ public static SerializedProperty GetSize(this SerializedProperty array)
472
490
return array . FindPropertyRelative ( "Array.size" ) ;
473
491
}
474
492
475
-
476
493
public static T GetAttribute < T > ( SerializedProperty property ) where T : Attribute
477
494
{
478
495
return GetAttribute < T > ( property , GetFieldInfo ( property , out _ ) ) ;
@@ -493,7 +510,6 @@ public static T[] GetAttributes<T>(SerializedProperty property, FieldInfo fieldI
493
510
return ( T [ ] ) fieldInfo . GetCustomAttributes ( typeof ( T ) , true ) ;
494
511
}
495
512
496
-
497
513
internal static void EnsureReflectionSafeness ( SerializedProperty property )
498
514
{
499
515
if ( property . serializedObject . hasModifiedProperties )
0 commit comments