File tree Expand file tree Collapse file tree 3 files changed +24
-5
lines changed
Expand file tree Collapse file tree 3 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -101,8 +101,20 @@ public void OnDisable()
101101 dynamicRegistered = false ;
102102 }
103103
104- public void OnDestroy ( ) =>
105- OnDisable ( ) ;
104+ public void OnDestroy ( )
105+ {
106+ if ( ! Application . isPlaying )
107+ return ;
108+
109+ if ( ! SceneConnectorRegistry . TryGet ( gameObject . scene , out var sceneConnector ) || sceneConnector == null )
110+ return ;
111+
112+ if ( ! sceneConnector . IsInitialized )
113+ return ;
114+
115+ sceneConnector . Unregister ( this ) ;
116+ dynamicRegistered = false ;
117+ }
106118
107119 internal void MarkStatic ( int sceneHandle ) =>
108120 staticSceneHandle = sceneHandle ;
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ private void DumpSceneIndex()
4747 private ServiceRegistry sceneContext ;
4848
4949 private readonly List < LocalConnector > dynamicConnectors = new ( capacity : 64 ) ;
50- private readonly HashSet < LocalConnector > dynamicSet = new ( ) ;
50+ private readonly HashSet < LocalConnector > dynamicSet = new ( ReferenceComparer < LocalConnector > . Instance ) ;
5151
5252 private readonly List < LocalConnector > pendingAdd = new ( capacity : 32 ) ;
5353 private readonly List < LocalConnector > pendingRemove = new ( capacity : 32 ) ;
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ public sealed class SceneEntityIndex
1717
1818 private readonly Dictionary < Type , List < MonoBehaviour > > nodeMap = new ( capacity : 256 ) ;
1919
20- private readonly HashSet < LocalConnector > registered = new ( ) ;
20+ private readonly HashSet < LocalConnector > registered = new ( ReferenceComparer < LocalConnector > . Instance ) ;
2121
2222 public int RegisteredCount => registered . Count ;
2323 public int IdCount => idMap . Count ;
@@ -262,7 +262,14 @@ private void UnregisterEntityKey(LocalConnector connector)
262262
263263 if ( ! string . IsNullOrEmpty ( key . Tag ) && tagMap . TryGetValue ( key . Tag , out var list ) && list != null )
264264 {
265- list . Remove ( connector ) ;
265+ for ( var i = list . Count - 1 ; i >= 0 ; i -- )
266+ {
267+ if ( ReferenceEquals ( list [ i ] , connector ) )
268+ {
269+ list . RemoveAt ( i ) ;
270+ break ;
271+ }
272+ }
266273
267274 if ( list . Count == 0 )
268275 tagMap . Remove ( key . Tag ) ;
You can’t perform that action at this time.
0 commit comments