diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs index c53cc8fe49..a2f755d807 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -632,6 +632,26 @@ public T this[int index] } } + /// + /// Gets a **zero‑allocation**, read‑only + /// 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. + /// + /// + /// A read‑only that shares + /// the same backing memory as this list. + /// + public NativeArray.ReadOnly AsNativeArray() + { + return m_List.AsReadOnly(); + } + private void HandleAddListEvent(NetworkListEvent listEvent) { m_DirtyEvents.Add(listEvent);