Skip to content

Commit 20310d4

Browse files
committed
Fixed various critical object spawning issues
1 parent 679c56a commit 20310d4

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
797797
uint networkId = messageReader.ReadUInt32();
798798
int ownerId = messageReader.ReadInt32();
799799
int prefabId = messageReader.ReadInt32();
800+
800801
if (isPlayerObject)
801802
{
802803
connectedClients.Add(ownerId, new NetworkedClient() { ClientId = ownerId });

MLAPI/NetworkingManagerComponents/Core/SpawnManager.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using MLAPI.MonoBehaviours.Core;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using UnityEngine;
@@ -170,12 +171,13 @@ internal static void OnSpawnObject(NetworkedObject netObject, int? clientOwnerId
170171
Debug.LogWarning("MLAPI: Server only objects does not have to be spawned");
171172
return;
172173
}
173-
else if (netManager.NetworkConfig.HandleObjectSpawning)
174+
else if (!netManager.NetworkConfig.HandleObjectSpawning)
174175
{
175176
Debug.LogWarning("MLAPI: NetworkingConfiguration is set to not handle object spawning");
176177
return;
177178
}
178179
uint netId = GetNetworkObjectId();
180+
netObject.networkId = netId;
179181
spawnedObjects.Add(netId, netObject);
180182
netObject.isSpawned = true;
181183
if (clientOwnerId != null)
@@ -192,11 +194,8 @@ internal static void OnSpawnObject(NetworkedObject netObject, int? clientOwnerId
192194
writer.Write(netObject.OwnerClientId);
193195
writer.Write(netObject.SpawnablePrefabIndex);
194196
}
195-
//If we are host, send to everyone except ourselves. Otherwise, send to all
196-
if (netManager.isHost)
197-
netManager.Send("MLAPI_ADD_OBJECT", "MLAPI_INTERNAL", stream.GetBuffer(), -1);
198-
else
199-
netManager.Send("MLAPI_ADD_OBJECT", "MLAPI_INTERNAL", stream.GetBuffer());
197+
198+
netManager.Send("MLAPI_ADD_OBJECT", "MLAPI_INTERNAL", stream.GetBuffer());
200199
}
201200
}
202201
}

0 commit comments

Comments
 (0)