File tree Expand file tree Collapse file tree
Packages/net.pawlygon.unitytools/Editor Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -344,14 +344,24 @@ private static T GetMember<T>(object target, string name) where T : class
344344 Type type = target . GetType ( ) ;
345345
346346 FieldInfo field = type . GetField ( name , flags ) ;
347- if ( field != null ) return field . GetValue ( target ) as T ;
347+ if ( field != null ) return AsLiveValue < T > ( field . GetValue ( target ) ) ;
348348
349349 PropertyInfo property = type . GetProperty ( name , flags ) ;
350- if ( property != null && property . GetIndexParameters ( ) . Length == 0 ) return property . GetValue ( target ) as T ;
350+ if ( property != null && property . GetIndexParameters ( ) . Length == 0 ) return AsLiveValue < T > ( property . GetValue ( target ) ) ;
351351
352352 return null ;
353353 }
354354
355+ /// <summary>
356+ /// An unassigned or destroyed Unity object field (e.g. a PhysBone with no Root Transform) reads back as a
357+ /// non-null placeholder that throws on use; return real null so callers' fallbacks apply.
358+ /// </summary>
359+ private static T AsLiveValue < T > ( object value ) where T : class
360+ {
361+ if ( value is UnityEngine . Object unityObject && unityObject == null ) return null ;
362+ return value as T ;
363+ }
364+
355365 // =====================================================================
356366 // Paths
357367 // =====================================================================
You can’t perform that action at this time.
0 commit comments