Skip to content

Commit 1584749

Browse files
authored
fix: m_ListAtLastReset and dynamically spawned objects (#2065)
1 parent ba30286 commit 1584749

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66

77
Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).
88

9+
## [Unreleased]
10+
11+
### Changed
12+
13+
### Fixed
14+
15+
- Fixed NetworkLists not populating on client. NetworkList now uses the most recent list as opposed to the list at the end of previous frame, when sending full updates to dynamically spawned NetworkObject. The difference in behaviour is required as scene management spawns those objects at a different time in the frame, relative to updates. (#2062)
16+
917
## [1.0.0] - 2022-06-27
1018

1119
### Changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,26 @@ public override void WriteDelta(FastBufferWriter writer)
122122
/// <inheritdoc />
123123
public override void WriteField(FastBufferWriter writer)
124124
{
125-
writer.WriteValueSafe((ushort)m_ListAtLastReset.Length);
126-
for (int i = 0; i < m_ListAtLastReset.Length; i++)
125+
// The listAtLastReset mechanism was put in place to deal with duplicate adds
126+
// upon initial spawn. However, it causes issues with in-scene placed objects
127+
// due to difference in spawn order. In order to address this, we pick the right
128+
// list based on the type of object.
129+
bool isSceneObject = m_NetworkBehaviour.NetworkObject.IsSceneObject != false;
130+
if (isSceneObject)
127131
{
128-
NetworkVariableSerialization<T>.Write(writer, ref m_ListAtLastReset.ElementAt(i));
132+
writer.WriteValueSafe((ushort)m_ListAtLastReset.Length);
133+
for (int i = 0; i < m_ListAtLastReset.Length; i++)
134+
{
135+
NetworkVariableSerialization<T>.Write(writer, ref m_ListAtLastReset.ElementAt(i));
136+
}
137+
}
138+
else
139+
{
140+
writer.WriteValueSafe((ushort)m_List.Length);
141+
for (int i = 0; i < m_List.Length; i++)
142+
{
143+
NetworkVariableSerialization<T>.Write(writer, ref m_List.ElementAt(i));
144+
}
129145
}
130146
}
131147

0 commit comments

Comments
 (0)