Search Unity

Feedback NetworkObjectReference can't be NULL though that seems like a perfectly valid use case

Discussion in 'Netcode for GameObjects' started by UnkelRambo, Dec 12, 2022.

  1. UnkelRambo

    UnkelRambo

    Joined:
    Oct 26, 2012
    Posts:
    80
    Hi!

    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<NetworkObjectReference> 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 ;)

    Thoughts?
     
  2. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hi @UnkelRambo , this seems a valid use case, thanks for sharing!

    Would you mind opening a feature request on the repository of Netcode For Gameobjects (you can do it from this link) and paste its link here?

    In this way, the NGO team will be able to prioritize this feature for future versions of the SDK.
     
    UnkelRambo likes this.
  3. UnkelRambo

    UnkelRambo

    Joined:
    Oct 26, 2012
    Posts:
    80
    Definitely, thanks!

    Submitted here:
    https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/2346

    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:
    https://forum.unity.com/threads/players-picking-up-objects-is-much-harder-than-it-should-be.1343492/
     
    Last edited: Dec 13, 2022
  4. Matthieu-POC

    Matthieu-POC

    Joined:
    Dec 14, 2022
    Posts:
    1
    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
     
  5. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Thank you so much, @UnkelRambo !

    Yes, please! It's the easiest way to make the team aware of the issue, especially if you can back the issue with a code sample

    Oooh, nice catch! I'm reporting this to Boss Room's team
     
  6. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204