MirrorNetworking / MirrorNetworking/Mirror

SyncVars fail to initialize correctly on host after multiple objects are spawned.

Open
#4,100 6 comments 0 reactions 1 assignee View on GitHub

@imerr is already working on this.

Since Mar 11, 2026.

Dominant language
C#
Stars
6.3k
Forks
870
PR merge metrics
No merged PRs in 30d

Description

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

  1. Use the MirrorBasic example as a starting point.
  2. Create a simple cube object in the scene, assign it a network identity and attach this script to it:
using UnityEngine;
using Mirror;

public class CubeTest : NetworkBehaviour
{
    [SyncVar(hook = nameof(UpdateHook))]
    public string testValue;

    public void UpdateHook(string oldI, string newI)
    {
        Debug.Log($"Old: {oldI}, New: {newI}");
    }
}

  1. Save this object as a prefab to assets, remove it from the scene, and add it to the network manager's registered spawnable prefabs.
  2. Create an empty scene object and assign to it a network identity and this script:
using Mirror;
using UnityEngine;

public class SpawnerTest : NetworkBehaviour
{
    public GameObject prefab;
    int repeatCount = 10;
    public override void OnStartServer()
    {
        base.OnStartServer();
        repeatCount = 10;
    }

    void Update()
    {
        if (repeatCount > 0)
        {
            GameObject g = Instantiate(prefab);
            NetworkServer.Spawn(g);
            g.GetComponent<CubeTest>().testValue = "test string";

            repeatCount--;
        }
    }
}
  1. Assign the cube prefab to the SpawnerTest component in the editor.
  2. Run the scene and click host.
  3. 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.
  4. If similar output isnt observed, maybe try increasing the repeatCount.
Image

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.