com.unity.netcode.gameobjects
com.unity.netcode.gameobjects copied to clipboard
OverflowException with NetworkVariable using InstantiateAndSpawn with Dedicated-Server
Description
OverFlowException when instantiating a object with networkvariables on it, using InstantiateAndSpawn when host is dedicated server
Reproduce Steps
- Make a dedicated server build
- Have a prefab with a NetworkVariable
- Have the server spawn the prefab using InstantiateAndSpawn
- 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
- OS: Windows 10
- Unity Version: 2023.2.5f1
- Netcode Version: 1.11.0
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/[email protected]/Runtime/NetworkVariable/NetworkVariableSerialization.cs:252)
Unity.Netcode.NetworkVariableSerialization1[T].Read (Unity.Netcode.FastBufferReader reader, T& value) (at ./Library/PackageCache/[email protected]/Runtime/NetworkVariable/NetworkVariableSerialization.cs:1623)
Unity.Netcode.NetworkVariable1[T].ReadField (Unity.Netcode.FastBufferReader reader) (at ./Library/PackageCache/[email protected]/Runtime/NetworkVariable/NetworkVariable.cs:260)
Unity.Netcode.NetworkBehaviour.SetNetworkVariableData (Unity.Netcode.FastBufferReader reader, System.UInt64 clientId) (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkBehaviour.cs:1123)
Unity.Netcode.NetworkObject.SetNetworkVariableData (Unity.Netcode.FastBufferReader reader, System.UInt64 clientId) (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkObject.cs:1521)
Unity.Netcode.NetworkObject.SynchronizeNetworkBehaviours[T] (Unity.Netcode.BufferSerializer1[T]& serializer, System.UInt64 targetClientId) (at ./Library/PackageCache/[email protected]/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/[email protected]/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/[email protected]/Runtime/Messaging/Messages/CreateObjectMessage.cs:54)
UnityEngine.Debug:LogException(Exception)
Unity.Netcode.CreateObjectMessage:CreateObject(NetworkManager&, UInt64, UInt32, SceneObject, FastBufferReader) (at ./Library/PackageCache/[email protected]/Runtime/Messaging/Messages/CreateObjectMessage.cs:59)
Unity.Netcode.CreateObjectMessage:Handle(NetworkContext&) (at ./Library/PackageCache/[email protected]/Runtime/Messaging/Messages/CreateObjectMessage.cs:45)
Unity.Netcode.NetworkMessageManager:ReceiveMessage(FastBufferReader, NetworkContext&, NetworkMessageManager) (at ./Library/PackageCache/[email protected]/Runtime/Messaging/NetworkMessageManager.cs:582)
Unity.Netcode.NetworkMessageManager:HandleMessage(NetworkMessageHeader&, FastBufferReader, UInt64, Single, Int32) (at ./Library/PackageCache/[email protected]/Runtime/Messaging/NetworkMessageManager.cs:446)
Unity.Netcode.NetworkMessageManager:ProcessIncomingMessageQueue() (at ./Library/PackageCache/[email protected]/Runtime/Messaging/NetworkMessageManager.cs:472)
Unity.Netcode.NetworkManager:NetworkUpdate(NetworkUpdateStage) (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkManager.cs:49)
Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage(NetworkUpdateStage) (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkUpdateLoop.cs:192)
Unity.Netcode.<>c:<CreateLoopSystem>b__0_0() (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkUpdateLoop.cs:215)```
Hi @joshturb To better understand this issue, could you provide:
- The
NetworkBehaviourthat contains theNetworkVariableproperty (or an example of that class/script) - The
NetworkBehaviourorMonoBehaviourthat was invokingNetworkObject.InstantiateAndSpawnorNetworkSpawnManager.InstantiateAndSpawn(or a culled version of that class/script so I can understand at what point this is being invoked).
The above information will help me replicate the issue on my end.
I'm closing this issue because its stale. Feel free to reopen if the issue persists or you have any new information