How can I prevent the NetworkVariable's OnValueChanged event from being triggered?

Hi folks.

The project has Multiplay and NFG.
I want to prevent OnValueChanged event when I change the NetworkVariable’s value. So, end of the game I want to reset all NetworkVariables without to trigger OnValueChanged.
I try to use “Reset()”, “SetDirty(true/false)”, “ResetDirty()”, but none of them working.
Actually, I don’t want to use extra variable to solve this problem. I must be easy way.

Unity version: 6000.0.26f1
NFG version : 2.1.1

Thanks.

Sounds like you are fixating on a solution to an issue which originates elsewhere.

For instance, there shouldn‘t be any need to „reset“ a NetworkVariable. It also shouldn‘t matter that a value change event triggers if you set each variable to zero because whoever is the receiver should not need to care about this event and either has unregistered the event or just does the usual like also „resetting“ the GUI state.

So, you mean that I can add a condition to the “OnValueChanged” event like this:

if(_networkVariable.value == defaultValue)
    return;

Actually I need to assign value without notification like in UIToolkit "SetValueWithoutNotify.
If I correct understand you, there isn’t any method like this. Is there?

No there isn’t, and there needn’t be.
I think you are in a situation where you are looking for a solution (don’t send event) where the better solution would be to, for instance, unsubscribe from events before the reset. Or send a notification “resetting” to everyone so they won’t handle these events in the “resetting” state.

But more importantly I question the reason for resetting. Perhaps you are using network variables where you shouldn’t have? Their main purpose is to allow for late joining clients to syncronize the state automatically. If you don’t have late joining clients you may want to prefer to synchronize state with RPCs. In that case, if you want to restart the game from beginning, all you’d have to do is to tell each client to “reset” and they can handle the rest.

Thanks for your answers @CodeSmile , it was a very useful chat for me.
Actually, when I completed the “restart” game structure, I realized that I didn’t need it.
Only I change GameState than all clients do what they have to do.