com.unity.netcode.gameobjects icon indicating copy to clipboard operation
com.unity.netcode.gameobjects copied to clipboard

NetworkObjectReference OnValueChanged callback

Open fernando-cortez opened this issue 3 years ago • 4 comments

Is your feature request related to a problem? Please describe. NetworkObjectReference should have a OnValueChanged callback, like a NetworkVariable does.

Describe the solution you'd like A callback added to NetworkObjectReference to listen to.

Describe alternatives you've considered Caching a reference to a NetworkObject's NetworkObjectId through NetworkVariable<ulong> is an alternative.

fernando-cortez avatar Aug 23 '22 18:08 fernando-cortez

I'm not sure I'm following the use case. Can you present a typical use?

The way I understand it, NetworkObjectReference is meant to be serialized. It is something you can send.

OnValueChanged is the paradigm we use for when you have an object that is synchronized between server and client. You want to be told when the other party changed it. Since you send a NetworkObjectReference and you don't share one, I don't see how the notification would be triggered.

Please elaborate :-).

jeffreyrainy avatar Aug 24 '22 18:08 jeffreyrainy

We use NetworkVariable in boss room for tracking pot pickup. This tracks the object id. We set it to 0 when dropping the pot and so we track value changes for this. It would have been cool if we could have used NetworkObjectReference for this instead of having to find the NetworkObject by id ourselves.

SamuelBellomo avatar Sep 21 '22 21:09 SamuelBellomo

@jeffreyrainy ^^^

SamuelBellomo avatar Sep 21 '22 21:09 SamuelBellomo

I don't think it is possible to change NetworkObjectReference to do what you want, not without making it into something entirely differently.

NetworkObjectReference is just a way to serialize a NetworkObject id. It doesn't have the synchornization part, that NetworkVariables have. Looking at the code, it doesn't even seem possible to change the object a NetworkObjectReference references. Rather, it is possible to create a new NetworkObjectReference, to a different object.

Logically, the closest one could have had would have been NetworkVariable<NetworkObjectReference>, but NetworkVariable only support where T : unmanaged, so it seems your are out of luck.

jeffreyrainy avatar Sep 21 '22 22:09 jeffreyrainy

On the develop branch, NetworkVariable<NetworkObjectReference> are now supported. You can use this if you need to synchronize a NetworkObjectReference between machines.

I'll close this, please re-open or file a new one if it turns out to be buggy or fall short of your expectations.

Thanks!

jeffreyrainy avatar Oct 04 '22 14:10 jeffreyrainy