Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question OverflowException: Reading past the end of the buffer with Network Variables

Discussion in 'Game Server Hosting' started by burgerandfries43, May 23, 2023.

  1. burgerandfries43

    burgerandfries43

    Joined:
    Jan 23, 2021
    Posts:
    8
    Hello,

    I have been attempting to make a damage system using Network Variables but I keep running into this issue whenever they are spawned. OverflowException: Reading past the end of the buffer. It only happens when the Network Variable is in the scene and just when it is serialized.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.Netcode;
    5. using System;
    6.  
    7. public class PlayerHealth : NetworkBehaviour
    8. {
    9.     public NetworkVariable<float> playerHealth;
    10.  
    11.     public override void OnNetworkSpawn()
    12.     {
    13.         playerHealth = new NetworkVariable<float>(100,
    14.         NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
    15.     }
    16.  
    17.     [ServerRpc(RequireOwnership = false)]
    18.     public void DoDamageServerRpc(float damage)
    19.     {
    20.         Debug.Log("Did " + damage + " damage");
    21.         playerHealth.Value -= damage;
    22.     }
    23. }
    This is the script it is in and it is on Multiplay Servers. Here is the full error message

    OverflowException: Reading past the end of the buffer
    Unity.Netcode.SceneEventData.DeserializeDespawnedInScenePlacedNetworkObjects () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/SceneManagement/SceneEventData.cs:852)
    Unity.Netcode.SceneEventData.SynchronizeSceneNetworkObjects (Unity.Netcode.NetworkManager networkManager) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/SceneManagement/SceneEventData.cs:890)
    Unity.Netcode.NetworkSceneManager.HandleClientSceneEvent (System.UInt32 sceneEventId) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/SceneManagement/NetworkSceneManager.cs:1781)
    Unity.Netcode.NetworkSceneManager.ClientLoadedSynchronization (System.UInt32 sceneEventId) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/SceneManagement/NetworkSceneManager.cs:1747)
    Unity.Netcode.NetworkSceneManager.OnClientBeginSync (System.UInt32 sceneEventId) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/SceneManagement/NetworkSceneManager.cs:1676)
    Unity.Netcode.NetworkSceneManager.HandleClientSceneEvent (System.UInt32 sceneEventId) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/SceneManagement/NetworkSceneManager.cs:1774)
    Unity.Netcode.NetworkSceneManager.HandleSceneEvent (System.UInt64 clientId, Unity.Netcode.FastBufferReader reader) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/SceneManagement/NetworkSceneManager.cs:1961)
    Unity.Netcode.SceneEventMessage.Handle (Unity.Netcode.NetworkContext& context) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Messaging/Messages/SceneEventMessage.cs:26)
    Unity.Netcode.MessagingSystem.ReceiveMessage[T] (Unity.Netcode.FastBufferReader reader, Unity.Netcode.NetworkContext& context, Unity.Netcode.MessagingSystem system) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Messaging/MessagingSystem.cs:511)
    Unity.Netcode.MessagingSystem.HandleMessage (Unity.Netcode.MessageHeader& header, Unity.Netcode.FastBufferReader reader, System.UInt64 senderId, System.Single timestamp, System.Int32 serializedHeaderSize) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Messaging/MessagingSystem.cs:384)
    UnityEngine.Debug:LogException(Exception)
    Unity.Netcode.MessagingSystem:HandleMessage(MessageHeader&, FastBufferReader, UInt64, Single, Int32) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Messaging/MessagingSystem.cs:388)
    Unity.Netcode.MessagingSystem:processIncomingMessageQueue() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Messaging/MessagingSystem.cs:404)
    Unity.Netcode.NetworkManager:OnNetworkEarlyUpdate() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Core/NetworkManager.cs:1600)
    Unity.Netcode.NetworkManager:NetworkUpdate(NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Core/NetworkManager.cs:1532)
    Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage(NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Core/NetworkUpdateLoop.cs:185)
    Unity.Netcode.<>c:<CreateLoopSystem>b__0_0() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Core/NetworkUpdateLoop.cs:208)

    Thank You