com.unity.netcode.gameobjects
com.unity.netcode.gameobjects copied to clipboard
NetworkVariable<FixedStringXBytes> sync issue on Ownership change
Description
We faced problem with syncing FixedStringXBytes of the NetworkBehaviour when changing ownership of the corresponding NetworkObject
There are no probmlems with other supported type (float, bool, INetworkSerializable struct)
Reproduce Steps
- Add next component to the project:
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
public class Sample : NetworkBehaviour
{
[SerializeField] private NetworkVariable<FixedString64Bytes> _string1 = new NetworkVariable<FixedString64Bytes>(string.Empty);
[SerializeField] private NetworkVariable<FixedString64Bytes> _string2 = new NetworkVariable<FixedString64Bytes>(string.Empty);
public override void OnNetworkSpawn()
{
if(IsServer)
{
_string1.Value = "QWERTY";
_string2.Value = "QWERTYASDFG";
}
}
}
- Add this component to any
NetworkObjecton scene - Start Host/Server (optionaly connect with a few clients; clients count doesn't matter)
- Change the ownership of the object (you can use server itself as an argument)
- Observe
OverflowException: Attempted to write without first calling TryBeginWrite()each frame
Actual Outcome
Error each frame on server side:
OverflowException: Attempted to write without first calling TryBeginWrite()
Unity.Netcode.FastBufferWriter.WriteByte (System.Byte value) (at ./Library/PackageCache/[email protected]/Runtime/Serialization/FastBufferWriter.cs:655)
Unity.Netcode.FixedStringSerializer`1[T].WriteDelta (Unity.Netcode.FastBufferWriter writer, T& value, T& previousValue) (at ./Library/PackageCache/[email protected]/Runtime/NetworkVariable/NetworkVariableSerialization.cs:720)
Unity.Netcode.NetworkVariableSerialization`1[T].WriteDelta (Unity.Netcode.FastBufferWriter writer, T& value, T& previousValue) (at ./Library/PackageCache/[email protected]/Runtime/NetworkVariable/NetworkVariableSerialization.cs:1642)
Unity.Netcode.NetworkVariable`1[T].WriteDelta (Unity.Netcode.FastBufferWriter writer) (at ./Library/PackageCache/[email protected]/Runtime/NetworkVariable/NetworkVariable.cs:198)
Unity.Netcode.NetworkVariableDeltaMessage.Serialize (Unity.Netcode.FastBufferWriter writer, System.Int32 targetVersion) (at ./Library/PackageCache/[email protected]/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs:111)
Unity.Netcode.NetworkBehaviour.NetworkVariableUpdate (System.UInt64 targetClientId, System.Int32 behaviourIndex) (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkBehaviour.cs:909)
Unity.Netcode.NetworkBehaviour.VariableUpdate (System.UInt64 targetClientId) (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkBehaviour.cs:860)
Unity.Netcode.NetworkBehaviourUpdater.NetworkBehaviourUpdate () (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkBehaviourUpdater.cs:57)
Unity.Netcode.NetworkBehaviourUpdater.NetworkBehaviourUpdater_Tick () (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkBehaviourUpdater.cs:129)
Unity.Netcode.NetworkTickSystem.UpdateTick (System.Double localTimeSec, System.Double serverTimeSec) (at ./Library/PackageCache/[email protected]/Runtime/Timing/NetworkTickSystem.cs:102)
Unity.Netcode.NetworkTimeSystem.UpdateTime () (at ./Library/PackageCache/[email protected]/Runtime/Timing/NetworkTimeSystem.cs:141)
Unity.Netcode.NetworkManager.NetworkUpdate (Unity.Netcode.NetworkUpdateStage updateStage) (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkManager.cs:57)
Unity.Netcode.NetworkUpdateLoop.RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage updateStage) (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkUpdateLoop.cs:192)
Unity.Netcode.NetworkUpdateLoop+NetworkPreUpdate+<>c.<CreateLoopSystem>b__0_0 () (at ./Library/PackageCache/[email protected]/Runtime/Core/NetworkUpdateLoop.cs:239)
Expected Outcome
Same behaviour as for other supported types
Environment
- OS: Windows 10
- Unity Version: 2023.2.18f1
- Netcode Version: 1.9.1
Hi @Fofanius,
I think this could have been resolved in #2953. Could you update your project's Packages\Manifest.json com.unity.netcode.gameobjects entry with the below modifications and let me know if you no longer experience this issue?
"com.unity.netcode.gameobjects": "https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git?path=com.unity.netcode.gameobjects#develop",
I'm going to close this issue because it's stale but feel free to reopen if the issue still exist