Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.1k stars 430 forks source link

feat: allows `NetworkObjectReference`s and `NetworkBehaviourReference`s to be null #2830

Closed SimoGecko closed 2 months ago

SimoGecko commented 4 months ago

Allows NetworkObjectReferences and NetworkBehaviourReferences to be null

This PR implements this request: https://forum.unity.com/threads/networkobjectreference-cant-be-null-though-that-seems-like-a-perfectly-valid-use-case.1373304/ which has its own issues https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/2346 and https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/1693

This PR adds support for NetworkObjectReference and NetworkBehaviourReference to be null. References in C# are allowed to be null, this should also be supported in these primitives. It's common, even in networked communication, to have to pass a null value to a function denoting the absence of something.

The nullId used to represent null is ulong.MaxValue = ~1.8e19, which seems to be large enough to avoid collision with normal use cases or special cases requiring further validation.

Changelog

Testing and Documentation

unity-cla-assistant commented 4 months ago

CLA assistant check
All committers have signed the CLA.

NoelStephensUnity commented 2 months ago

This PR's changes were migrated over to the public repository in #2874. These updates will be include in the next v1.9.0 release. Closing out this PR. Thank you for your submission!