Repository navigation
NetworkVariable modified in OnNetworkSpawn (Server) sends default value in initial CreateObjectMessage #3876
Description
Activity
- addedtype:bugBug ReportBug Reportstat:awaiting-triageStatus - Awaiting triage from the Netcode team.Status - Awaiting triage from the Netcode team.stat:reply-neededAwaiting reply from Unity accountAwaiting reply from Unity account
on Feb 10, 2026 - addedpriority:highThis issue has high priority and we are focusing to resolve itThis issue has high priority and we are focusing to resolve itstat:importStatus - Issue is going to be saved internallyStatus - Issue is going to be saved internallyregressionThe issue is a regression (something that was working in previous version)The issue is a regression (something that was working in previous version)and removedstat:awaiting-triageStatus - Awaiting triage from the Netcode team.Status - Awaiting triage from the Netcode team.
on Feb 10, 2026 HI @LaPluses,
Thank you for bringing this to our attention. It would seem this was a regression bug I introduced in #3799. Apologies for the inconvenience. PR #3878 should resolve this issue but is still a WIP.
We will be releasing a hot-patch update for this once the fix has finished passing tests and been merged (i.e. you should see this pretty quickly since it is a regression issue).
Reacted by Ke Shen- addedstat:awaiting-responseAwaiting response from author. This label should be added manually.Awaiting response from author. This label should be added manually.stat:InvestigatingIssue is currently being investigatedIssue is currently being investigatedand removedstat:reply-neededAwaiting reply from Unity accountAwaiting reply from Unity account
on Feb 10, 2026 - removedstat:InvestigatingIssue is currently being investigatedIssue is currently being investigated
on Feb 11, 2026 - addedstat:importedStatus - Issue is tracked internally at UnityStatus - Issue is tracked internally at Unityand removedstat:importStatus - Issue is going to be saved internallyStatus - Issue is going to be saved internally
on Feb 11, 2026 - removedstat:awaiting-responseAwaiting response from author. This label should be added manually.Awaiting response from author. This label should be added manually.
on Feb 11, 2026 @LaPluses
At this time you should be able to update your package by name (i.e. com.unity.netcode.gameobjects) and for the version use 2.9.2. It should show up in the package manager by tomorrow.The fix for this issue is in both v2.8.2 and v2.9.2+.
If you run into any problems regarding this issue please feel free to post here or to open a new issue.
Thank you for in-depth description of the issue and your patience while I resolved this regression bug.Happy netcoding!
😸
Reacted by Ke ShenReacted by Ke Shen@NoelStephensUnity , Thank you for the incredibly quick response and for getting this fixed so fast!
It's really a weird fundamental bug(;, appreciate your hard work(also thanks to the Gemini AI. 😂
The following content were rewritten by AI to improve the readability.
Root Cause Analysis was done with Gemini CLI(model: gemini-3-pro), i personally manually check on it, though am not familar with the codebase, so please treat these findings as a starting point for further validation.
Description
When a
NetworkVariableis modified within theOnNetworkSpawnmethod on the Server immediately after spawning aNetworkObject, the connecting Client receives the default/initial value (e.g., 0) in the initialCreateObjectMessage, rather than the modified value (e.g., 2).Although the correct value is eventually synchronized via a subsequent
NetworkVariableDeltaMessage, this causes a race condition where the Client sees the incorrect value during its ownOnNetworkSpawnand initial frame execution.Reproduce Steps
NetworkBehaviourwith aNetworkVariable<float>(default value 0).OnNetworkSpawn. Inside the method, checkif (IsServer)and set the variable to a new value (e.g.,2).NetworkObject.Spawn().NetworkVariableon the Client side inside the Client'sOnNetworkSpawnmethod or immediately after spawn.Actual Outcome
The Client receives the default value (0) in the initial spawn packet. The correct value (2) arrives late in a subsequent delta update. This breaks initialization logic dependent on the initial state of NetworkVariables.
Expected Outcome
The Client should receive the modified value (2) contained within the initial
CreateObjectMessageso thatOnNetworkSpawnon the client has the correct state immediately.Screenshots
If applicable, add screenshots to help explain your problem.
Environment
Additional Context
Minimal Reproduction Code:
Root Cause Analysis:
We have investigated the internal execution flow and identified the issue in the serialization logic relative to
OnNetworkSpawntiming:Spawn()is called,NetworkVariable.Initializecaptures the default value (0) asm_PreviousValueand setsm_HasPreviousValue = true.OnNetworkSpawnis called on the Server. The user setsTestVal.Value = 2. This marks the variable as Dirty, butm_PreviousValueremains 0.CreateObjectMessage,NetworkVariable<T>.WriteFieldSynchronizationis called.0. The "new" value2is queued for a delta update. The client initializes with0before the delta arrives.