Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.15k stars 435 forks source link

OverflowException with NetworkVariable using InstantiateAndSpawn with Dedicated-Server #3079

Open joshturb opened 2 months ago

joshturb commented 2 months ago

Description

OverFlowException when instantiating a object with networkvariables on it, using InstantiateAndSpawn when host is dedicated server

Reproduce Steps

  1. Make a dedicated server build
  2. Have a prefab with a NetworkVariable
  3. Have the server spawn the prefab using InstantiateAndSpawn
  4. See error

Actual Outcome

OverflowException: Reading past the end of the buffer, Error server spawns player but chokes on the declaration of the networkvariable no matter what the network variable is it will not work, unless it was a scene object.

Expected Outcome

It behaves normally initializing the network variable

Environment

Additional Context

It was fixed by instantiating then using obj.SpawnAsPlayer(clientId) instead of InstantiateAndSpawn

Full Error:


Unity.Netcode.UnmanagedTypeSerializer1[T].Read (Unity.Netcode.FastBufferReader reader, T& value) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/NetworkVariable/NetworkVariableSerialization.cs:252)
Unity.Netcode.NetworkVariableSerialization1[T].Read (Unity.Netcode.FastBufferReader reader, T& value) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/NetworkVariable/NetworkVariableSerialization.cs:1623)
Unity.Netcode.NetworkVariable1[T].ReadField (Unity.Netcode.FastBufferReader reader) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/NetworkVariable/NetworkVariable.cs:260)
Unity.Netcode.NetworkBehaviour.SetNetworkVariableData (Unity.Netcode.FastBufferReader reader, System.UInt64 clientId) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/Core/NetworkBehaviour.cs:1123)
Unity.Netcode.NetworkObject.SetNetworkVariableData (Unity.Netcode.FastBufferReader reader, System.UInt64 clientId) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/Core/NetworkObject.cs:1521)
Unity.Netcode.NetworkObject.SynchronizeNetworkBehaviours[T] (Unity.Netcode.BufferSerializer1[T]& serializer, System.UInt64 targetClientId) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/Core/NetworkObject.cs:1794)
Unity.Netcode.NetworkObject.AddSceneObject (Unity.Netcode.NetworkObject+SceneObject& sceneObject, Unity.Netcode.FastBufferReader reader, Unity.Netcode.NetworkManager networkManager) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/Core/NetworkObject.cs:1943)
Unity.Netcode.CreateObjectMessage.CreateObject (Unity.Netcode.NetworkManager& networkManager, System.UInt64 senderId, System.UInt32 messageSize, Unity.Netcode.NetworkObject+SceneObject sceneObject, Unity.Netcode.FastBufferReader networkVariableData) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/Messaging/Messages/CreateObjectMessage.cs:54)
UnityEngine.Debug:LogException(Exception)
Unity.Netcode.CreateObjectMessage:CreateObject(NetworkManager&, UInt64, UInt32, SceneObject, FastBufferReader) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/Messaging/Messages/CreateObjectMessage.cs:59)
Unity.Netcode.CreateObjectMessage:Handle(NetworkContext&) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/Messaging/Messages/CreateObjectMessage.cs:45)
Unity.Netcode.NetworkMessageManager:ReceiveMessage(FastBufferReader, NetworkContext&, NetworkMessageManager) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/Messaging/NetworkMessageManager.cs:582)
Unity.Netcode.NetworkMessageManager:HandleMessage(NetworkMessageHeader&, FastBufferReader, UInt64, Single, Int32) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/Messaging/NetworkMessageManager.cs:446)
Unity.Netcode.NetworkMessageManager:ProcessIncomingMessageQueue() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/Messaging/NetworkMessageManager.cs:472)
Unity.Netcode.NetworkManager:NetworkUpdate(NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/Core/NetworkManager.cs:49)
Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage(NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/Core/NetworkUpdateLoop.cs:192)
Unity.Netcode.<>c:<CreateLoopSystem>b__0_0() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.11.0/Runtime/Core/NetworkUpdateLoop.cs:215)```
NoelStephensUnity commented 2 months ago

Hi @joshturb To better understand this issue, could you provide:

The above information will help me replicate the issue on my end.