Skip to content

Commit 8bac8aa

Browse files
authored
fix: NetworkList "insert at end" bug (#2099)
1 parent a0525e6 commit 8bac8aa

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2121
- Fixed IsServer and IsClient being set to false before object despawn during the shutdown sequence. (#2074)
2222
- 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)
2323
- Fixed NetworkList Value event on the server. PreviousValue is now set correctly when a new value is set through property setter. (#2067)
24+
- Fixed NetworkList issue that showed when inserting at the very end of a NetworkList (#2099)
2425

2526
## [1.0.0] - 2022-06-27
2627

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,16 @@ public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta)
196196
{
197197
reader.ReadValueSafe(out int index);
198198
NetworkVariableSerialization<T>.Read(reader, out T value);
199-
m_List.InsertRangeWithBeginEnd(index, index + 1);
200-
m_List[index] = value;
199+
200+
if (index < m_List.Length)
201+
{
202+
m_List.InsertRangeWithBeginEnd(index, index + 1);
203+
m_List[index] = value;
204+
}
205+
else
206+
{
207+
m_List.Add(value);
208+
}
201209

202210
if (OnListChanged != null)
203211
{
@@ -419,8 +427,15 @@ public int IndexOf(T item)
419427
/// <inheritdoc />
420428
public void Insert(int index, T item)
421429
{
422-
m_List.InsertRangeWithBeginEnd(index, index + 1);
423-
m_List[index] = item;
430+
if (index < m_List.Length)
431+
{
432+
m_List.InsertRangeWithBeginEnd(index, index + 1);
433+
m_List[index] = item;
434+
}
435+
else
436+
{
437+
m_List.Add(item);
438+
}
424439

425440
var listEvent = new NetworkListEvent<T>()
426441
{

0 commit comments

Comments
 (0)