Skip to content

Commit 17b769d

Browse files
Merge branch 'develop-2.0.0' into feat/attachable-networkbehaviour-and-object-controller
2 parents a63de0b + 1de6174 commit 17b769d

File tree

9 files changed

+805
-532
lines changed

9 files changed

+805
-532
lines changed

.yamato/_triggers.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,20 @@
4545
# Since standards job is a part of initial checks it's not present as direct dependency here!!!!!!!!!!!!!!!!!!!!
4646
pull_request_trigger:
4747
name: Pull Request Trigger (develop, develop-2.0.0, & release branches)
48+
# Run the following tests on a selection of different desktop platforms
4849
dependencies:
49-
# Run package EditMode and Playmode package tests on trunk
50-
- .yamato/_run-all.yml#run_all_package_tests_trunk
51-
# Run package EditMode and Playmode package tests on minimum supported editor (6000.0 in case of NGOv2.X)
52-
- .yamato/_run-all.yml#run_all_package_tests_6000
53-
# Run project EditMode and Playmode project tests on trunk
54-
- .yamato/_run-all.yml#run_all_project_tests_trunk
55-
# Run project EditMode and Playmode project tests on minimum supported editor (6000.0 in case of NGOv2.X)
56-
- .yamato/_run-all.yml#run_all_project_tests_6000
57-
# Run standalone test. Run windows standalone tests as this is our most common platform, and run ubuntu rust tests.
50+
# Run package EditMode and Playmode package tests on trunk and an older supported editor (6000.0)
51+
- .yamato/package-tests.yml#package_test_-_ngo_trunk_mac
52+
- .yamato/package-tests.yml#package_test_-_ngo_6000.0_win
53+
54+
# Run testproject EditMode and Playmode project tests on trunk and an older supported editor (6000.0)
55+
- .yamato/project-tests.yml#test_testproject_win_trunk
56+
- .yamato/project-tests.yml#test_testproject_mac_6000.0
57+
58+
# Run standalone test. We run it only on Ubuntu since it's the fastest machine, and it was noted that for example distribution on macOS is taking 40m since we switched to Apple Silicon
5859
# Coverage on other standalone machines is present in Nightly job so it's enough to not run all of them for PRs
5960
- .yamato/desktop-standalone-tests.yml#desktop_standalone_test_testproject_win_il2cpp_6000.0
60-
- .yamato/cmb-service-standalone-tests.yml#cmb_service_standalone_test_testproject_ubuntu_il2cpp_6000.0
61+
- .yamato/cmb-service-standalone-tests.yml#cmb_service_standalone_test_testproject_ubuntu_il2cpp_trunk
6162
triggers:
6263
cancel_old_ci: true
6364
pull_requests:

.yamato/project.metafile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# The small agent was created to handle jobs that don't involve running Unity and are in general super light when it comes to resource usage (for example pack job).
2020
# It uses ubuntu since Linux VMs are faster and cheaper to provision than Mac or Windows Virtual Machines (VMs).
2121
# The b1.small flavour is nearly always sufficient for jobs that don’t involve running Unity Editor.
22-
small_agent_platform:
22+
small_agent_platform:
2323
- name: ubuntu
2424
type: Unity::VM
2525
image: package-ci/ubuntu-22.04:v4
@@ -40,7 +40,7 @@ test_platforms:
4040
image: package-ci/ubuntu-22.04:v4
4141
flavor: b1.large
4242
standalone: StandaloneLinux64
43-
desktop:
43+
desktop:
4444
- name: ubuntu
4545
type: Unity::VM
4646
image: package-ci/ubuntu-22.04:v4
@@ -146,7 +146,7 @@ test_platforms:
146146
image: package-ci/win10-xbox:v4
147147
flavor: b1.large
148148
standalone: GameCoreScarlett
149-
149+
150150
# EDITOR CONFIGURATIONS-------------------------------------------------------------------------------
151151
# Editors to be used for testing. NGOv2.X official support started from 6000.0 editor
152152
# TODO: When a new editor will be released it should be added to this list
@@ -156,13 +156,14 @@ validation_editors:
156156
- trunk
157157
all:
158158
- 6000.0
159-
- 6000.1
159+
- 6000.1
160+
- 6000.2
160161
- trunk
161-
162-
162+
163+
163164
# Scripting backends used by Standalone RunTimeTests---------------------------------------------------
164165

165-
scripting_backends:
166+
scripting_backends:
166167
- mono
167168
- il2cpp
168169

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Additional documentation and release notes are available at [Multiplayer Documen
1919

2020
### Fixed
2121

22+
- Fixed regression issue in v2.x where `NetworkObject.GetNetworkBehaviourAtOrderIndex` was converted from public to internal. (#3541)
23+
- Fixed ensuring OnValueChanged callback is still triggered on the authority when a collection changes and then reverts to the previous value in the same frame. (#3539)
2224
- Fixed synchronizing the destroyGameObject parameter to clients for InScenePlaced network objects. (#3514)
2325
- Fixed distributed authority related issue where enabling the `NetworkObject.DestroyWithScene` would cause errors when a destroying non-authority instances due to loading (single mode) or unloading scene events. (#3500)
2426

com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2768,7 +2768,12 @@ public ushort GetNetworkBehaviourOrderIndex(NetworkBehaviour instance)
27682768
return 0;
27692769
}
27702770

2771-
internal NetworkBehaviour GetNetworkBehaviourAtOrderIndex(ushort index)
2771+
/// <summary>
2772+
/// Returns the <see cref="NetworkBehaviour"/> at the ordered index value which can be obtained using <see cref="GetNetworkBehaviourOrderIndex"/>.
2773+
/// </summary>
2774+
/// <param name="index">The order index value of the <see cref="NetworkBehaviour"/>.</param>
2775+
/// <returns>The <see cref="NetworkBehaviour"/> at the ordered index value or null if it does not exist.</returns>
2776+
public NetworkBehaviour GetNetworkBehaviourAtOrderIndex(ushort index)
27722777
{
27732778
if (index >= ChildNetworkBehaviours.Count)
27742779
{

com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public override void OnInitialize()
5757
base.OnInitialize();
5858

5959
m_HasPreviousValue = true;
60-
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_InternalOriginalValue);
60+
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_LastInternalValue);
6161
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_PreviousValue);
6262
}
6363

@@ -73,7 +73,7 @@ public NetworkVariable(T value = default,
7373
: base(readPerm, writePerm)
7474
{
7575
m_InternalValue = value;
76-
m_InternalOriginalValue = default;
76+
m_LastInternalValue = default;
7777
// Since we start with IsDirty = true, this doesn't need to be duplicated
7878
// right away. It won't get read until after ResetDirty() is called, and
7979
// the duplicate will be made there. Avoiding calling
@@ -92,25 +92,45 @@ public void Reset(T value = default)
9292
if (m_NetworkBehaviour == null || m_NetworkBehaviour != null && !m_NetworkBehaviour.NetworkObject.IsSpawned)
9393
{
9494
m_InternalValue = value;
95-
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_InternalOriginalValue);
95+
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_LastInternalValue);
9696
m_PreviousValue = default;
9797
}
9898
}
9999

100100
/// <summary>
101-
/// The internal value of the NetworkVariable
101+
/// The current internal value of the NetworkVariable.
102102
/// </summary>
103+
/// <remarks>
104+
/// When using collections, this InternalValue can be updated directly without going through the <see cref="NetworkVariable{T}.Value"/> setter.
105+
/// </remarks>
103106
[SerializeField]
104107
private protected T m_InternalValue;
105108

106-
// The introduction of standard .NET collections caused an issue with permissions since there is no way to detect changes in the
107-
// collection without doing a full comparison. While this approach does consume more memory per collection instance, it is the
108-
// lowest risk approach to resolving the issue where a client with no write permissions could make changes to a collection locally
109-
// which can cause a myriad of issues.
110-
private protected T m_InternalOriginalValue;
109+
/// <summary>
110+
/// The last valid/authorized value of the network variable.
111+
/// </summary>
112+
/// <remarks>
113+
/// The introduction of standard .NET collections caused an issue with permissions since there is no way to detect changes in the
114+
/// collection without doing a full comparison. While this approach does consume more memory per collection instance, it is the
115+
/// lowest risk approach to resolving the issue where a client with no write permissions could make changes to a collection locally
116+
/// which can cause a myriad of issues.
117+
/// </remarks>
118+
private protected T m_LastInternalValue;
111119

120+
/// <summary>
121+
/// The most recent value that was synchronized over the network.
122+
/// Synchronized over the network at the end of the frame in which the <see cref="NetworkVariable{T}"/> was marked dirty.
123+
/// </summary>
124+
/// <remarks>
125+
/// Only contains the value synchronized over the network at the end of the last frame.
126+
/// All in-between changes on the authority are tracked by <see cref="m_LastInternalValue"/>.
127+
/// </remarks>
112128
private protected T m_PreviousValue;
113129

130+
/// <summary>
131+
/// Whether this network variable has had changes synchronized over the network.
132+
/// Indicates whether <see cref="m_PreviousValue"/> is populated and valid.
133+
/// </summary>
114134
private bool m_HasPreviousValue;
115135
private bool m_IsDisposed;
116136

@@ -139,7 +159,7 @@ public virtual T Value
139159
{
140160
T previousValue = m_InternalValue;
141161
m_InternalValue = value;
142-
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_InternalOriginalValue);
162+
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_LastInternalValue);
143163
SetDirty(true);
144164
m_IsDisposed = false;
145165
OnValueChanged?.Invoke(previousValue, m_InternalValue);
@@ -165,20 +185,21 @@ public bool CheckDirtyState(bool forceCheck = false)
165185
if (CannotWrite)
166186
{
167187
// If modifications are detected, then revert back to the last known current value
168-
if (!NetworkVariableSerialization<T>.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue))
188+
if (!NetworkVariableSerialization<T>.AreEqual(ref m_InternalValue, ref m_LastInternalValue))
169189
{
170-
NetworkVariableSerialization<T>.Duplicate(m_InternalOriginalValue, ref m_InternalValue);
190+
NetworkVariableSerialization<T>.Duplicate(m_LastInternalValue, ref m_InternalValue);
171191
}
172192
return false;
173193
}
174194

175-
// Compare the previous with the current if not dirty or forcing a check.
176-
if ((!isDirty || forceCheck) && !NetworkVariableSerialization<T>.AreEqual(ref m_PreviousValue, ref m_InternalValue))
195+
// Compare the last internal value with the current value if not dirty or forcing a check.
196+
if ((!isDirty || forceCheck) && !NetworkVariableSerialization<T>.AreEqual(ref m_LastInternalValue, ref m_InternalValue))
177197
{
178198
SetDirty(true);
179-
OnValueChanged?.Invoke(m_PreviousValue, m_InternalValue);
199+
OnValueChanged?.Invoke(m_LastInternalValue, m_InternalValue);
180200
m_IsDisposed = false;
181201
isDirty = true;
202+
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_LastInternalValue);
182203
}
183204
return isDirty;
184205
}
@@ -212,11 +233,11 @@ public override void Dispose()
212233
m_InternalValue = default;
213234

214235
// Dispose the internal original value
215-
if (m_InternalOriginalValue is IDisposable internalOriginalValueDisposable)
236+
if (m_LastInternalValue is IDisposable internalOriginalValueDisposable)
216237
{
217238
internalOriginalValueDisposable.Dispose();
218239
}
219-
m_InternalOriginalValue = default;
240+
m_LastInternalValue = default;
220241

221242
// Dispose the previous value if there is one
222243
if (m_HasPreviousValue && m_PreviousValue is IDisposable previousValueDisposable)
@@ -245,9 +266,9 @@ public override bool IsDirty()
245266
{
246267
// If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert
247268
// to the original collection value prior to applying updates (primarily for collections).
248-
if (!NetworkUpdaterCheck && CannotWrite && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue))
269+
if (!NetworkUpdaterCheck && CannotWrite && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalValue, ref m_LastInternalValue))
249270
{
250-
NetworkVariableSerialization<T>.Duplicate(m_InternalOriginalValue, ref m_InternalValue);
271+
NetworkVariableSerialization<T>.Duplicate(m_LastInternalValue, ref m_InternalValue);
251272
return true;
252273
}
253274
// For most cases we can use the dirty flag.
@@ -284,7 +305,7 @@ public override void ResetDirty()
284305
m_HasPreviousValue = true;
285306
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_PreviousValue);
286307
// Once updated, assure the original current value is updated for future comparison purposes
287-
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_InternalOriginalValue);
308+
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_LastInternalValue);
288309
}
289310
base.ResetDirty();
290311
}
@@ -307,9 +328,9 @@ public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta)
307328
{
308329
// If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert
309330
// to the original collection value prior to applying updates (primarily for collections).
310-
if (CannotWrite && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue))
331+
if (CannotWrite && !NetworkVariableSerialization<T>.AreEqual(ref m_LastInternalValue, ref m_InternalValue))
311332
{
312-
NetworkVariableSerialization<T>.Duplicate(m_InternalOriginalValue, ref m_InternalValue);
333+
NetworkVariableSerialization<T>.Duplicate(m_LastInternalValue, ref m_InternalValue);
313334
}
314335

315336
NetworkVariableSerialization<T>.ReadDelta(reader, ref m_InternalValue);
@@ -341,17 +362,17 @@ internal override void PostDeltaRead()
341362
m_HasPreviousValue = true;
342363
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_PreviousValue);
343364
// Once updated, assure the original current value is updated for future comparison purposes
344-
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_InternalOriginalValue);
365+
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_LastInternalValue);
345366
}
346367

347368
/// <inheritdoc />
348369
public override void ReadField(FastBufferReader reader)
349370
{
350371
// If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert
351372
// to the original collection value prior to applying updates (primarily for collections).
352-
if (CannotWrite && !NetworkVariableSerialization<T>.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue))
373+
if (CannotWrite && !NetworkVariableSerialization<T>.AreEqual(ref m_LastInternalValue, ref m_InternalValue))
353374
{
354-
NetworkVariableSerialization<T>.Duplicate(m_InternalOriginalValue, ref m_InternalValue);
375+
NetworkVariableSerialization<T>.Duplicate(m_LastInternalValue, ref m_InternalValue);
355376
}
356377

357378
NetworkVariableSerialization<T>.Read(reader, ref m_InternalValue);
@@ -363,7 +384,7 @@ public override void ReadField(FastBufferReader reader)
363384
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_PreviousValue);
364385

365386
// Once updated, assure the original current value is updated for future comparison purposes
366-
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_InternalOriginalValue);
387+
NetworkVariableSerialization<T>.Duplicate(m_InternalValue, ref m_LastInternalValue);
367388
}
368389

369390
/// <inheritdoc />

0 commit comments

Comments
 (0)