File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
MLAPI/MonoBehaviours/Core Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,12 @@ internal set
109
109
110
110
internal uint sceneSpawnedInIndex = 0 ;
111
111
112
+ /// <summary>
113
+ /// Wheter or not to destroy this object if it's owner is destroyed.
114
+ /// If false, the objects ownership will be given to the server.
115
+ /// </summary>
116
+ public bool DontDestroyWithOwner ;
117
+
112
118
private void OnDestroy ( )
113
119
{
114
120
if ( NetworkingManager . Singleton != null )
Original file line number Diff line number Diff line change @@ -966,14 +966,24 @@ internal void OnClientDisconnectFromServer(uint clientId)
966
966
967
967
if ( ConnectedClients . ContainsKey ( clientId ) )
968
968
{
969
- if ( NetworkConfig . HandleObjectSpawning )
969
+ if ( IsServer && NetworkConfig . HandleObjectSpawning )
970
970
{
971
971
if ( ConnectedClients [ clientId ] . PlayerObject != null )
972
972
Destroy ( ConnectedClients [ clientId ] . PlayerObject . gameObject ) ;
973
+
973
974
for ( int i = 0 ; i < ConnectedClients [ clientId ] . OwnedObjects . Count ; i ++ )
974
975
{
975
976
if ( ConnectedClients [ clientId ] . OwnedObjects [ i ] != null )
976
- Destroy ( ConnectedClients [ clientId ] . OwnedObjects [ i ] . gameObject ) ;
977
+ {
978
+ if ( ! ConnectedClients [ clientId ] . OwnedObjects [ i ] . DontDestroyWithOwner )
979
+ {
980
+ Destroy ( ConnectedClients [ clientId ] . OwnedObjects [ i ] . gameObject ) ;
981
+ }
982
+ else
983
+ {
984
+ ConnectedClients [ clientId ] . OwnedObjects [ i ] . RemoveOwnership ( ) ;
985
+ }
986
+ }
977
987
}
978
988
}
979
989
@@ -985,6 +995,7 @@ internal void OnClientDisconnectFromServer(uint clientId)
985
995
break ;
986
996
}
987
997
}
998
+
988
999
ConnectedClients . Remove ( clientId ) ;
989
1000
}
990
1001
You can’t perform that action at this time.
0 commit comments