1515public partial class BasisAvatarSDKInspector : Editor
1616{
1717 private const string PendingTestInEditorAvatarIdSessionKey = "BasisAvatarSDKInspector.PendingTestInEditorAvatarId" ;
18+ // Unity's GlobalObjectId table isn't always populated on the first delayCall after
19+ // EnteredPlayMode (the play-mode scene reload races us). Retry a bounded number of
20+ // ticks so a transient null resolve doesn't drop the pending avatar.
21+ private const int MaxResolveAttempts = 30 ;
22+ private static int _resolveAttempts ;
1823
1924 public delegate void BeforeTestInEditorHandler ( GameObject clone ) ;
2025 public static BeforeTestInEditorHandler OnBeforeTestInEditor ;
@@ -50,6 +55,7 @@ private static void OnPlayModeStateChanged(PlayModeStateChange state)
5055 return ;
5156 }
5257
58+ _resolveAttempts = 0 ;
5359 EditorApplication . delayCall -= TryExecutePendingTestInEditor ;
5460 EditorApplication . delayCall += TryExecutePendingTestInEditor ;
5561 }
@@ -59,23 +65,34 @@ private static void TryExecutePendingTestInEditor()
5965 string pendingAvatarId = GetPendingTestInEditorAvatarId ( ) ;
6066 if ( string . IsNullOrEmpty ( pendingAvatarId ) )
6167 {
68+ _resolveAttempts = 0 ;
6269 return ;
6370 }
6471
6572 if ( ! GlobalObjectId . TryParse ( pendingAvatarId , out GlobalObjectId avatarId ) )
6673 {
6774 ClearPendingTestInEditorAvatarId ( ) ;
75+ _resolveAttempts = 0 ;
6876 return ;
6977 }
7078
7179 BasisAvatar avatar = GlobalObjectId . GlobalObjectIdentifierToObjectSlow ( avatarId ) as BasisAvatar ;
72- ClearPendingTestInEditorAvatarId ( ) ;
7380 if ( avatar == null )
7481 {
75- BasisDebug . LogError ( "Unable to resolve the pending avatar for Test In Editor." , BasisDebug . LogTag . Editor ) ;
82+ if ( ++ _resolveAttempts < MaxResolveAttempts )
83+ {
84+ EditorApplication . delayCall += TryExecutePendingTestInEditor ;
85+ return ;
86+ }
87+
88+ ClearPendingTestInEditorAvatarId ( ) ;
89+ _resolveAttempts = 0 ;
90+ BasisDebug . LogError ( $ "Unable to resolve the pending avatar for Test In Editor after { MaxResolveAttempts } attempts.", BasisDebug . LogTag . Editor ) ;
7691 return ;
7792 }
7893
94+ ClearPendingTestInEditorAvatarId ( ) ;
95+ _resolveAttempts = 0 ;
7996 RequestAvatarLoad ( avatar ) ;
8097 }
8198
0 commit comments