I was scratching my head a bit working on some pickup/throwing mechanics for my game, and I realized that NetworkObjectReference throws an exception (which my ability system was kindly eating and not rethrowing, whoops ^_^) if the NetworkObject passed to the constructor is NULL.
My exact use-case is this:
When a character picks up an object, I’m tracking the carried object via a NetworkVariable and using that as a quick “validation” mechanism for networked gameplay. I also have some other code (namely the “drop object” ability) that checks for a valid carried object and sets it to NULL. This is the broken bit because NetworkObjectReference CAN’T be NULL.
I’ve done this a lot with other abilities I’ve built as a really quick form of Server RPC receipt validation, but this is the first time I’ve used NetworkObjectReference like this.
This seems like a totally valid use case to me that would be sweet if supported! Right now I’m using this as a NetworkVariable, so as a workaround I added a NullableNetworkObjectReference type that’s copy+pasta of NetworkObjectReference, just with NULL support
I also just hit a similar use-case trying to parent a NetworkObject to NULL, which is stated as a valid case in the documentation but the source explicitly disallows NULL parents. Should I open a separate request for that or add it to the request for NetworkObjectReference?
Thanks again
Edit: In fact, funny enough, the “parenting to NULL” case ISN’T handled in the BossRoom demo drop action, as described here:
Just got the same problem during a UNET migration. At some point a RPC send a GameObject that could be null
(in our case something like ‘Destroyed( GameObject src)’ and having no src is perfectly fine)
Currently need to split into 2 rpcs or using a special ‘empty’ gameobject created for this : no very handy