private static Exception FKCtrlLateUpdateCleanupFinalizer(FKCtrl __instance, NullReferenceException __exception) { if (__exception == null) { return(null); } Common.Utilities.Logger.LogInfo("Cleaning up destroyed objects from FKCtrl.listBones"); var fk = Traverse.Create(__instance); var boneList = fk.Field("listBones").GetValue <IList>(); foreach (var targetInfo in boneList.Cast <object>().ToList()) { if (Traverse.Create(targetInfo).Field("gameObject").GetValue <GameObject>() == null) { boneList.Remove(targetInfo); } } fk.Property("count").SetValue(boneList.Count); return(null); }