-
-
Notifications
You must be signed in to change notification settings - Fork 846
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
- 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:
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}");
}
}- Save this object as a prefab to assets, remove it from the scene, and add it to the network manager's registered spawnable prefabs.
- 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--;
}
}
}- 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.