-
Notifications
You must be signed in to change notification settings - Fork 460
Automatically invoke NetworkVariable.OnValueChanged when spawning #3186
Copy link
Copy link
Open
Labels
TrackingHas been added to trackingHas been added to trackingpriority:mediumThis issue has medium priority and may take some time to be resolvedThis issue has medium priority and may take some time to be resolvedstat:reply-neededAwaiting reply from Unity accountAwaiting reply from Unity accounttype:featureNew feature, request or improvementNew feature, request or improvementtype:feature-2.xNew NGO 2.0.0 feature, request or improvementNew NGO 2.0.0 feature, request or improvement
Metadata
Metadata
Assignees
Labels
TrackingHas been added to trackingHas been added to trackingpriority:mediumThis issue has medium priority and may take some time to be resolvedThis issue has medium priority and may take some time to be resolvedstat:reply-neededAwaiting reply from Unity accountAwaiting reply from Unity accounttype:featureNew feature, request or improvementNew feature, request or improvementtype:feature-2.xNew NGO 2.0.0 feature, request or improvementNew NGO 2.0.0 feature, request or improvement
Type
Fields
Give feedbackNo fields configured for issues without a type.
Feedback
When load scene with in-scene placed
NetworkObjector dynamically spawnNetworkObject, connected client would spawn the object andNetworkVariablevalue synced with the server. But theOnValueChangedis not called, even if the value has been synced with the value of server, and is different from the default value that has been set inNetworkBehaviour. The current behavior of skippingOnValueChangedwhen spawning also doesn't depend on where theOnValueChangedhas been registered, inOnNetworkSpawn,OnNetworkPreSpawnor even inAwake.This caused a lot of problems, because
NetworkVariablemay be a bool that enable/disable a renderer, or set a shader field throughOnValueChanged. SkippingOnValueChangedwould make render frame inconsistent with what's intended. This is specially annoying when late-join client starts to spawn allNetworkObject, withoutOnValueChangedthe game states would drastically different from server. The problem also shows up when a previouslyNetworkHideobject become visible again and client respwan the object but with inconsistent states from server.Suggested Changes
When spawning, all
NetworkVariableshould be synchronized, and correspondingOnValueChangedshould all get called, because clients are supposed to keep the same states as server. The server has likely changed the value ofNetworkVariableand have already called theOnValueChangedon server side, so when spawning happens, client need to not only sync all values ofNetworkVariable, but also call allOnValueChangedto keep the same states as server.An intuitive way is to register
OnValueChangedinOnNetworkPreSpawn, so that during subsequent spawning any valid callbacks registered will get called.