diff --git a/Assets/Mirror/Runtime/ClientScene.cs b/Assets/Mirror/Runtime/ClientScene.cs index dc3579d59..f8e1d24b4 100644 --- a/Assets/Mirror/Runtime/ClientScene.cs +++ b/Assets/Mirror/Runtime/ClientScene.cs @@ -220,6 +220,7 @@ internal static void RegisterSystemHandlers(NetworkClient client, bool localClie // LocalClient shares the sim/scene with the server, no need for these events client.RegisterHandler(MsgType.SpawnPrefab, OnSpawnPrefab); client.RegisterHandler(MsgType.SpawnSceneObject, OnSpawnSceneObject); + client.RegisterHandler(MsgType.SpawnStarted, OnObjectSpawnStarted); client.RegisterHandler(MsgType.SpawnFinished, OnObjectSpawnFinished); client.RegisterHandler(MsgType.ObjectDestroy, OnObjectDestroy); client.RegisterHandler(MsgType.ObjectHide, OnObjectDestroy); @@ -511,17 +512,17 @@ static void OnSpawnSceneObject(NetworkMessage netMsg) ApplySpawnPayload(spawnedId, msg.position, msg.rotation, msg.payload, msg.netId); } + static void OnObjectSpawnStarted(NetworkMessage netMsg) + { + if (LogFilter.Debug) { Debug.Log("SpawnStarted"); } + + PrepareToSpawnSceneObjects(); + s_IsSpawnFinished = false; + } + static void OnObjectSpawnFinished(NetworkMessage netMsg) { - ObjectSpawnFinishedMessage msg = netMsg.ReadMessage(); - if (LogFilter.Debug) { Debug.Log("SpawnFinished:" + msg.state); } - - if (msg.state == 0) - { - PrepareToSpawnSceneObjects(); - s_IsSpawnFinished = false; - return; - } + if (LogFilter.Debug) { Debug.Log("SpawnFinished"); } // paul: Initialize the objects in the same order as they were initialized // in the server. This is important if spawned objects diff --git a/Assets/Mirror/Runtime/Messages.cs b/Assets/Mirror/Runtime/Messages.cs index 6572d6298..b91760c5d 100644 --- a/Assets/Mirror/Runtime/Messages.cs +++ b/Assets/Mirror/Runtime/Messages.cs @@ -249,21 +249,9 @@ public override void Serialize(NetworkWriter writer) } } - // TODO use ByteMessage or use a SpawnStarted/Finished message. - class ObjectSpawnFinishedMessage : MessageBase - { - public byte state; // byte because it's always 0 or 1 + class ObjectSpawnStartedMessage : EmptyMessage {} - public override void Deserialize(NetworkReader reader) - { - state = reader.ReadByte(); - } - - public override void Serialize(NetworkWriter writer) - { - writer.Write(state); - } - } + class ObjectSpawnFinishedMessage : EmptyMessage {} class ObjectDestroyMessage : MessageBase { diff --git a/Assets/Mirror/Runtime/NetworkServer.cs b/Assets/Mirror/Runtime/NetworkServer.cs index f57898052..768cef798 100644 --- a/Assets/Mirror/Runtime/NetworkServer.cs +++ b/Assets/Mirror/Runtime/NetworkServer.cs @@ -717,9 +717,7 @@ public static void SetClientReady(NetworkConnection conn) // Spawn/update all current server objects if (LogFilter.Debug) { Debug.Log("Spawning " + NetworkIdentity.spawned.Count + " objects for conn " + conn.connectionId); } - ObjectSpawnFinishedMessage msg = new ObjectSpawnFinishedMessage(); - msg.state = 0; - conn.Send((short)MsgType.SpawnFinished, msg); + conn.Send((short)MsgType.SpawnStarted, new ObjectSpawnStartedMessage()); foreach (NetworkIdentity identity in NetworkIdentity.spawned.Values) { @@ -742,8 +740,7 @@ public static void SetClientReady(NetworkConnection conn) } } - msg.state = 1; - conn.Send((short)MsgType.SpawnFinished, msg); + conn.Send((short)MsgType.SpawnFinished, new ObjectSpawnFinishedMessage()); } internal static void ShowForConnection(NetworkIdentity identity, NetworkConnection conn) diff --git a/Assets/Mirror/Runtime/UNetwork.cs b/Assets/Mirror/Runtime/UNetwork.cs index 5508fc614..05b9f2c2e 100644 --- a/Assets/Mirror/Runtime/UNetwork.cs +++ b/Assets/Mirror/Runtime/UNetwork.cs @@ -35,6 +35,7 @@ public enum MsgType : short UpdateVars = 8, SpawnPrefab = 3, SpawnSceneObject = 10, + SpawnStarted = 11, SpawnFinished = 12, ObjectHide = 13, LocalClientAuthority = 15,