NetworkObjectReference OnValueChanged callback
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.
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 :-).
We use NetworkVariable
@jeffreyrainy ^^^
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.
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!