Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OverflowException with NetworkVariable using InstantiateAndSpawn with Dedicated-Server #3079

Open
joshturb opened this issue Sep 26, 2024 · 1 comment
Labels
stat:awaiting response Status - Awaiting response from author. stat:awaiting triage Status - Awaiting triage from the Netcode team. type:bug Bug Report

Comments

@joshturb
Copy link

joshturb commented Sep 26, 2024

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

  • 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/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)```
@joshturb joshturb added stat:awaiting triage Status - Awaiting triage from the Netcode team. type:bug Bug Report labels Sep 26, 2024
@joshturb joshturb changed the title OverflowException with Dedicated-Server and Network Variables OverflowException with NetworkVariable using InstantiateAndSpawn with Dedicated-Server Sep 26, 2024
@NoelStephensUnity
Copy link
Collaborator

NoelStephensUnity commented Sep 26, 2024

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

  • The NetworkBehaviour that contains the NetworkVariable property (or an example of that class/script)
  • The NetworkBehaviour or MonoBehaviour that was invoking NetworkObject.InstantiateAndSpawn or NetworkSpawnManager.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.

@NoelStephensUnity NoelStephensUnity added the stat:awaiting response Status - Awaiting response from author. label Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting response Status - Awaiting response from author. stat:awaiting triage Status - Awaiting triage from the Netcode team. type:bug Bug Report
Projects
None yet
Development

No branches or pull requests

2 participants