@@ -444,6 +444,7 @@ public List<Scene> GetSynchronizedScenes()
444
444
internal Dictionary < int , int > ServerSceneHandleToClientSceneHandle = new Dictionary < int , int > ( ) ;
445
445
internal Dictionary < int , int > ClientSceneHandleToServerSceneHandle = new Dictionary < int , int > ( ) ;
446
446
447
+ internal bool IsRestoringSession ;
447
448
/// <summary>
448
449
/// Add the client to server (and vice versa) scene handle lookup.
449
450
/// Add the client-side handle to scene entry in the HandleToScene table.
@@ -455,7 +456,7 @@ internal bool UpdateServerClientSceneHandle(int serverHandle, int clientHandle,
455
456
{
456
457
ServerSceneHandleToClientSceneHandle . Add ( serverHandle , clientHandle ) ;
457
458
}
458
- else
459
+ else if ( ! IsRestoringSession )
459
460
{
460
461
return false ;
461
462
}
@@ -464,7 +465,7 @@ internal bool UpdateServerClientSceneHandle(int serverHandle, int clientHandle,
464
465
{
465
466
ClientSceneHandleToServerSceneHandle . Add ( clientHandle , serverHandle ) ;
466
467
}
467
- else
468
+ else if ( ! IsRestoringSession )
468
469
{
469
470
return false ;
470
471
}
@@ -1045,7 +1046,7 @@ internal NetworkObject GetSceneRelativeInSceneNetworkObject(uint globalObjectIdH
1045
1046
/// <param name="targetClientIds">array of client identifiers to receive the scene event message</param>
1046
1047
private void SendSceneEventData ( uint sceneEventId , ulong [ ] targetClientIds )
1047
1048
{
1048
- if ( targetClientIds . Length == 0 )
1049
+ if ( targetClientIds . Length == 0 && ! NetworkManager . DistributedAuthorityMode )
1049
1050
{
1050
1051
// This would be the Host/Server with no clients connected
1051
1052
// Silently return as there is nothing to be done
@@ -1056,6 +1057,16 @@ private void SendSceneEventData(uint sceneEventId, ulong[] targetClientIds)
1056
1057
1057
1058
if ( NetworkManager . DistributedAuthorityMode && ! NetworkManager . DAHost )
1058
1059
{
1060
+ if ( NetworkManager . DistributedAuthorityMode && HasSceneAuthority ( ) )
1061
+ {
1062
+ sceneEvent . TargetClientId = NetworkManager . ServerClientId ;
1063
+ var message = new SceneEventMessage
1064
+ {
1065
+ EventData = sceneEvent ,
1066
+ } ;
1067
+ var size = NetworkManager . ConnectionManager . SendMessage ( ref message , k_DeliveryType , NetworkManager . ServerClientId ) ;
1068
+ NetworkManager . NetworkMetrics . TrackSceneEventSent ( NetworkManager . ServerClientId , ( uint ) sceneEvent . SceneEventType , SceneNameFromHash ( sceneEvent . SceneHash ) , size ) ;
1069
+ }
1059
1070
foreach ( var clientId in targetClientIds )
1060
1071
{
1061
1072
sceneEvent . TargetClientId = clientId ;
@@ -2430,6 +2441,12 @@ private void HandleClientSceneEvent(uint sceneEventId)
2430
2441
networkObject . InternalNetworkSessionSynchronized ( ) ;
2431
2442
}
2432
2443
2444
+ if ( NetworkManager . DistributedAuthorityMode && HasSceneAuthority ( ) && IsRestoringSession )
2445
+ {
2446
+ IsRestoringSession = false ;
2447
+ PostSynchronizationSceneUnloading = m_OriginalPostSynchronizationSceneUnloading ;
2448
+ }
2449
+
2433
2450
EndSceneEvent ( sceneEventId ) ;
2434
2451
}
2435
2452
break ;
@@ -2616,6 +2633,8 @@ private void HandleSessionOwnerEvent(uint sceneEventId, ulong clientId)
2616
2633
/// </summary>
2617
2634
internal bool SkipSceneHandling ;
2618
2635
2636
+ private bool m_OriginalPostSynchronizationSceneUnloading ;
2637
+
2619
2638
/// <summary>
2620
2639
/// Both Client and Server: Incoming scene event entry point
2621
2640
/// </summary>
@@ -2689,6 +2708,12 @@ internal void HandleSceneEvent(ulong clientId, FastBufferReader reader)
2689
2708
// Only if ClientSynchronizationMode is Additive and the client receives a synchronize scene event
2690
2709
if ( ClientSynchronizationMode == LoadSceneMode . Additive )
2691
2710
{
2711
+ if ( NetworkManager . DistributedAuthorityMode && HasSceneAuthority ( ) && IsRestoringSession && clientId == NetworkManager . ServerClientId )
2712
+ {
2713
+ m_OriginalPostSynchronizationSceneUnloading = PostSynchronizationSceneUnloading ;
2714
+ PostSynchronizationSceneUnloading = true ;
2715
+ }
2716
+
2692
2717
// Check for scenes already loaded and create a table of scenes already loaded (SceneEntries) that will be
2693
2718
// used if the server is synchronizing the same scenes (i.e. if a matching scene is already loaded on the
2694
2719
// client side, then that scene will be used as opposed to loading another scene). This allows for clients
0 commit comments