From 30b0cfb7862a13f1dd1ef96ac8f9c30de80039a6 Mon Sep 17 00:00:00 2001 From: Yuto Harada Date: Mon, 28 Jul 2025 18:55:48 +0900 Subject: [PATCH 1/2] 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 c53cc8fe49..ac25b1cae2 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -632,6 +632,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 d51b2aaea8c043563d3941bdf6b00d6e43c9a269 Mon Sep 17 00:00:00 2001 From: Yuto Harada Date: Thu, 31 Jul 2025 01:49:30 +0900 Subject: [PATCH 2/2] 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 ac25b1cae2..a2f755d807 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -633,12 +633,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();