@@ -26,6 +26,8 @@ public class TypeReference : ISerializationCallbackReceiver
2626
2727 private Type _type ;
2828
29+ private bool _needToLogTypeNotFound ;
30+
2931 /// <summary>
3032 /// Initializes a new instance of the <see cref="TypeReference"/> class with Type equal to null.
3133 /// </summary>
@@ -86,13 +88,15 @@ void ISerializationCallbackReceiver.OnAfterDeserialize()
8688 _type = IsNotEmpty ( TypeNameAndAssembly ) ? TryGetTypeFromSerializedFields ( ) : null ;
8789#if UNITY_EDITOR
8890 EditorApplication . delayCall += TryUpdatingTypeUsingGUID ;
91+ EditorApplication . delayCall += LogTypeNotFoundIfNeeded ;
8992#endif
9093 }
9194
9295 void ISerializationCallbackReceiver . OnBeforeSerialize ( )
9396 {
9497#if UNITY_EDITOR
9598 EditorApplication . delayCall -= TryUpdatingTypeUsingGUID ;
99+ EditorApplication . delayCall -= LogTypeNotFoundIfNeeded ;
96100#endif
97101 }
98102
@@ -177,6 +181,19 @@ private void TryUpdatingTypeUsingGUID()
177181 private void LogTypeNotFound ( ) =>
178182 Debug . LogWarning ( $ "'{ TypeNameAndAssembly } ' was referenced but such type was not found.") ;
179183
184+ /// <summary>
185+ /// Sometimes, the fact that the type disappeared is found during the deserialization. A warning cannot be
186+ /// logged during the deserialization, so it must be delayed with help of this method.
187+ /// </summary>
188+ private void LogTypeNotFoundIfNeeded ( )
189+ {
190+ if ( ! _needToLogTypeNotFound )
191+ return ;
192+
193+ LogTypeNotFound ( ) ;
194+ _needToLogTypeNotFound = false ;
195+ }
196+
180197 private void SetClassGuidIfExists ( Type type )
181198 {
182199 try
@@ -197,7 +214,7 @@ private Type TryGetTypeFromSerializedFields()
197214
198215 // If GUID is not empty, there is still hope the type will be found in the TryUpdatingTypeUsingGUID method.
199216 if ( type == null && GUID == string . Empty )
200- LogTypeNotFound ( ) ;
217+ _needToLogTypeNotFound = true ;
201218
202219 return type ;
203220 }
0 commit comments