From bb17920791dd8b7ad7551a90744ad859640bb090 Mon Sep 17 00:00:00 2001 From: vis2k Date: Fri, 1 Apr 2022 23:44:27 +0800 Subject: [PATCH] test for #3129 --- .../Tests/Editor/SyncVarAttributeTest.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Assets/Mirror/Tests/Editor/SyncVarAttributeTest.cs b/Assets/Mirror/Tests/Editor/SyncVarAttributeTest.cs index 49df52805..af3d72dfd 100644 --- a/Assets/Mirror/Tests/Editor/SyncVarAttributeTest.cs +++ b/Assets/Mirror/Tests/Editor/SyncVarAttributeTest.cs @@ -34,6 +34,11 @@ class SyncVarNetworkBehaviour : NetworkBehaviour [SyncVar] public SyncVarNetworkBehaviour value; } + class SyncVarSetByRef : NetworkBehaviour + { + [SyncVar] + public int value; + } class SyncVarAbstractNetworkBehaviour : NetworkBehaviour { public abstract class MockMonsterBase : NetworkBehaviour @@ -420,5 +425,22 @@ public void TestSyncingAbstractNetworkBehaviour() Assert.That(clientBehaviour.monster1, Is.EqualTo(serverBehaviour.monster1), "Data should be synchronized"); Assert.That(clientBehaviour.monster2, Is.EqualTo(serverBehaviour.monster2), "Data should be synchronized"); } + + // test to prevent https://github.com/vis2k/Mirror/issues/3129 + [Test] + public void SyncsIfSetByRef() + { + CreateNetworkedAndSpawn( + out _, out _, out SyncVarSetByRef serverObject, + out _, out _, out SyncVarSetByRef clientObject); + + // set it by ref on the server + void Setter(out int value) => value = 42; + Setter(out serverObject.value); + + // should sync to client + ProcessMessages(); + Assert.That(clientObject.value, Is.EqualTo(42)); + } } }