-
Notifications
You must be signed in to change notification settings - Fork 455
feat: add AsNativeArray()
read‑only accessor to `NetworkList<T>
#3562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you so much for your contribution! To add surface area to the Netcode for GameObjects package we have the requirement that every function needs to have C# code documentation. Do you think you can add that code documentation to this new function? |
Thank you for the review. Just to confirm, by "C# code documentation," are you referring to XML comments? I had originally included them, but I've edited them using the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's my bad for reviewing too fast. I did mean the XML docs. These expanded docs are great!
Next steps: I will port this PR over to an internal branch so we can run our internal tests against it. I'll close this PR when I open the internal one, Github will link everything together so you can track the progress if you'd like
Before I close this, do you mind confirming if you need this to land in an editor version that is older than Unity 6? Our team is trying to limit the new API surface area that we add to the older versions of the package. |
In my use case, support for versions earlier than Unity 6 is not required. So either way is fine for me — is that what you're asking? As for the NGO, we currently require |
…3567) Continues: #3562 from @harayuu9 This PR exposes the contents of a `NetworkList<T>` as a **read‑only `NativeArray<T>`**. It addresses the recurring need to interoperate efficiently with Burst‑compiled or `IJob`‑based code without paying the cost of element‑wise copies or allocations. The accessor simply forwards `m_List.AsReadOnly()`, preserving zero‑allocation semantics while respecting `NativeArray`’s lifetime constraints (call‑site must guarantee the list is not mutated or disposed). No behavioural changes are introduced—only a pure additive surface‑area expansion. ## Changelog - Added: `NetworkList<T>.AsNativeArray()` to return the list contents as a `NativeArray<T>.ReadOnly`. ## Testing and Documentation - No tests have been added. - Includes documentation for the newly added public API function. ## Backport This adds a new API surface area and so no backport is required. --------- Co-authored-by: Yuto Harada <[email protected]>
This PR exposes the contents of a
NetworkList<T>
as a read‑onlyNativeArray<T>
.It addresses the recurring need to interoperate efficiently with Burst‑compiled or
IJob
‑based code without paying the cost of element‑wise copies or allocations.The accessor simply forwards
m_List.AsReadOnly()
, preserving zero‑allocation semantics while respectingNativeArray
’s lifetime constraints (call‑site must guarantee the list is not mutated or disposed).No behavioural changes are introduced—only a pure additive surface‑area expansion.
Changelog
com.unity.netcode.gameobjects
NetworkList<T>.AsNativeArray()
→ returns the list contents as aNativeArray<T>.ReadOnly
.Testing and Documentation