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.16k
stars
435
forks
source link
feat: allows `NetworkObjectReference`s and `NetworkBehaviourReference`s to be null #2830
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
Added: support for NetworkObjectReference and NetworkBehaviourReference to be null, which in turn also allows passing null GameObjects or Behaviours to remote calls.
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!
Allows
NetworkObjectReference
s andNetworkBehaviourReference
s to be nullThis 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
andNetworkBehaviourReference
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 representnull
isulong.MaxValue
= ~1.8e19, which seems to be large enough to avoid collision with normal use cases or special cases requiring further validation.Changelog
NetworkObjectReference
andNetworkBehaviourReference
to be null, which in turn also allows passing null GameObjects or Behaviours to remote calls.Testing and Documentation