Skip to content

Commit 29fe501

Browse files
committed
Added DontDestroyWithOwner flag on NetworkedObject
1 parent 2d851a9 commit 29fe501

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

MLAPI/MonoBehaviours/Core/NetworkedObject.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ internal set
109109

110110
internal uint sceneSpawnedInIndex = 0;
111111

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+
112118
private void OnDestroy()
113119
{
114120
if (NetworkingManager.Singleton != null)

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,14 +966,24 @@ internal void OnClientDisconnectFromServer(uint clientId)
966966

967967
if (ConnectedClients.ContainsKey(clientId))
968968
{
969-
if(NetworkConfig.HandleObjectSpawning)
969+
if (IsServer && NetworkConfig.HandleObjectSpawning)
970970
{
971971
if (ConnectedClients[clientId].PlayerObject != null)
972972
Destroy(ConnectedClients[clientId].PlayerObject.gameObject);
973+
973974
for (int i = 0; i < ConnectedClients[clientId].OwnedObjects.Count; i++)
974975
{
975976
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+
}
977987
}
978988
}
979989

@@ -985,6 +995,7 @@ internal void OnClientDisconnectFromServer(uint clientId)
985995
break;
986996
}
987997
}
998+
988999
ConnectedClients.Remove(clientId);
9891000
}
9901001

0 commit comments

Comments
 (0)