You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SyncVars fail to initialize correctly on host after multiple objects are spawned. #4100
Describe the bug
On a host, instantiate a prefab, spawn it, then assign the value of a non-primitive type syncvar on the spawned object. If you loop this process a few times, the syncvar starts losing the assigned value on new objects.
[IMPORTANT] How can we reproduce the issue, step by step:
Please tell us how to reproduce your issue, STEP BY STEP, with one of our built in examples.
-> Tell us every single click / key press so we can reproduce it
-> If it can't be reproduced with our built in examples, tell us what else to do
-> Explain like we are five
Use the MirrorBasic example as a starting point.
Create a simple cube object in the scene, assign it a network identity and attach this script to it:
Assign the cube prefab to the SpawnerTest component in the editor.
Run the scene and click host.
Observe the console output for the UpdateHook's log statements. After the first few objects are spawned, the output should change. Example output from my system is below.
If similar output isnt observed, maybe try increasing the repeatCount.
Expected behavior
A clear and concise description of what you expected to happen. All of these logs should consistently show "test string" as the value of the syncvar for both the old and new parameters.
CORRECTION: All of these logs should show blank for the old value and "test string" for the new value.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
OS: Windows
Build target: Windows (observed in editor)
Unity version: 6000.3.10f1
Mirror branch: 96.9.19
Repro project, open the mirror/basic/scenes/MirrorBasic.unity scene. Mirror 96.9.19 Bug.zip
Additional context
Add any other context about the problem here.
If you switch your string sync var change to before the network spawn, it works btw.
g.GetComponent().testValue = "test string";
NetworkServer.Spawn(g);
Usually you want to set the sync variable before network spawning, does doing it this way solve your case?
Otherwise yes, I get same behaviour.
(or optionally, set via the objects script which triggers once its spawned in)
Small update, I observed the same effect on in-scene objects that get their syncvar values assigned to them by other in-scene objects in OnStartServer. This doesn't happen for self assigning where an object assigns its own syncvar a value in its own OnStartServer function. However even in that case it still shows the assigned parameter as both the old and new value in the hook function.
I was able to reproduce the exact same log output as @Roshinator on the latest Mirror version.
With the PR from @MrGadget1024 the output was as following:
Interestingly it just logs two hooks and the SyncVars of the other eight (after the Player in hirachy) are not set as shown in the other image.
Following the suggestion from JesusLuvsYooh, switching the lines of code results in no log at all but all objects have their variables correctly set.
GameObjectg=Instantiate(prefab);NetworkServer.Spawn(g);g.GetComponent<CubeTest>().testValue="test string";// Results in two logs and eight missingGameObjectg=Instantiate(prefab);g.GetComponent<CubeTest>().testValue="test string";NetworkServer.Spawn(g);// Results in no log but every objects SyncVar is correctly set
Activity
JesusLuvsYooh commentedon Mar 11, 2026
If you switch your string sync var change to before the network spawn, it works btw.

g.GetComponent().testValue = "test string";
NetworkServer.Spawn(g);
Usually you want to set the sync variable before network spawning, does doing it this way solve your case?
Otherwise yes, I get same behaviour.
(or optionally, set via the objects script which triggers once its spawned in)
MrGadget1024 commentedon Mar 11, 2026
Incorrect...they should all have nothing for old and "test string" for new value
Roshinator commentedon Mar 12, 2026
Small update, I observed the same effect on in-scene objects that get their syncvar values assigned to them by other in-scene objects in OnStartServer. This doesn't happen for self assigning where an object assigns its own syncvar a value in its own OnStartServer function. However even in that case it still shows the assigned parameter as both the old and new value in the hook function.
MrGadget1024 commentedon Apr 3, 2026
Please see if PR #4107 fixes this issue.
Nietod commentedon Apr 3, 2026
I was able to reproduce the exact same log output as @Roshinator on the latest Mirror version.
With the PR from @MrGadget1024 the output was as following:
Interestingly it just logs two hooks and the SyncVars of the other eight (after the Player in hirachy) are not set as shown in the other image.
Following the suggestion from JesusLuvsYooh, switching the lines of code results in no log at all but all objects have their variables correctly set.
MrGadget1024 commentedon Apr 6, 2026
I've made some progress on this in my local repo, but still some work to do.