From 7d0485295ab315130fa500f4e1788eed313f4fe5 Mon Sep 17 00:00:00 2001 From: Yuto Harada Date: Mon, 28 Jul 2025 18:55:48 +0900 Subject: [PATCH 1/4] add asNativeArray NetworkList --- .../NetworkVariable/Collections/NetworkList.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs index 1a78fc7f81..f57053a993 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -631,6 +631,18 @@ public T this[int index] } } + /// + /// Returns the contents of the NetworkList as a read-only NativeArray. + /// + /// + /// This method returns the list contents as a NativeArray.ReadOnly. Be careful with the lifetime of the NativeArray. + /// + /// A read-only NativeArray of the list contents. + public NativeArray.ReadOnly AsNativeArray() + { + return m_List.AsReadOnly(); + } + private void HandleAddListEvent(NetworkListEvent listEvent) { m_DirtyEvents.Add(listEvent); From b692313c64835026644c61692f10a88c49fa4413 Mon Sep 17 00:00:00 2001 From: Yuto Harada Date: Thu, 31 Jul 2025 01:49:30 +0900 Subject: [PATCH 2/4] comment with see cref --- .../NetworkVariable/Collections/NetworkList.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs index f57053a993..4cb8c08f08 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -632,12 +632,20 @@ public T this[int index] } /// - /// Returns the contents of the NetworkList as a read-only NativeArray. + /// Gets a **zero‑allocation**, read‑only + /// view over the current + /// elements of this . /// /// - /// This method returns the list contents as a NativeArray.ReadOnly. Be careful with the lifetime of the NativeArray. + /// The returned array stays valid **only until** the list is mutated (add, remove, + /// clear, resize) or the container is d. Continuing to use + /// it afterwards results in undefined behaviour; callers are responsible for + /// ensuring a safe lifetime. /// - /// A read-only NativeArray of the list contents. + /// + /// A read‑only that shares + /// the same backing memory as this list. + /// public NativeArray.ReadOnly AsNativeArray() { return m_List.AsReadOnly(); From 4f43776385181be30ff2e071e38e610c4c61d102 Mon Sep 17 00:00:00 2001 From: Emma Date: Wed, 30 Jul 2025 16:06:53 -0400 Subject: [PATCH 3/4] xml doc updates --- .../NetworkVariable/Collections/NetworkList.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs index 4cb8c08f08..9f0382c26a 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -632,19 +632,17 @@ public T this[int index] } /// - /// Gets a **zero‑allocation**, read‑only - /// view over the current + /// Gets a **zero‑allocation**, view over the current /// elements of this . /// /// /// The returned array stays valid **only until** the list is mutated (add, remove, - /// clear, resize) or the container is d. Continuing to use - /// it afterwards results in undefined behaviour; callers are responsible for - /// ensuring a safe lifetime. + /// clear, resize) or is called on the container. Continuing to use + /// the array after it is invalid will result in undefined behaviour; + /// callers are responsible for ensuring a safe lifetime. /// /// - /// A read‑only that shares - /// the same backing memory as this list. + /// A reference that shares the same backing memory as this list. /// public NativeArray.ReadOnly AsNativeArray() { From 03bb611ba2bf2aa6b1c1c1def9d1fe0c4a488120 Mon Sep 17 00:00:00 2001 From: Emma Date: Wed, 30 Jul 2025 16:12:24 -0400 Subject: [PATCH 4/4] Update CHANGELOG --- com.unity.netcode.gameobjects/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index 489af4f446..e1d003ee2b 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -10,6 +10,7 @@ Additional documentation and release notes are available at [Multiplayer Documen ### Added +- Added `AsNativeArray()` read‑only accessor to `NetworkList` (#3567) - Added serializer for `Pose` (#3546) - Added methods `GetDefaultNetworkSettings` and `GetDefaultPipelineConfigurations` to `UnityTransport`. These can be used to retrieve the default settings and pipeline stages that are used by `UnityTransport`. This is useful when providing a custom driver constructor through `UnityTransport.s_DriverConstructor`, since it allows reusing or tuning the existing configuration instead of trying to recreate it. This means a transport with a custom driver can now easily benefit from most of the features of `UnityTransport`, like integration with the Network Simulator and Network Profiler from the multiplayer tools package. (#3501) - Added mappings between `ClientId` and `TransportId`. (#3516)