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

Reconnected client not receiving NetworkVariable updates

Open ben-magicn opened this issue 3 years ago • 7 comments

Describe the bug When a client is disconnected from the server and then reconnects from within the same running game instance, it is possible for them to not receive any NetworkVariable updates from NetworkObjects. The client still has the old value that was set when they reconnected, and when the value is changed on the server, the following warning message is displayed on the client:

Deferred messages were received for NetworkObject #, but it did not spawn within 1 second.

If the client is closed, reopened, and then reconnects to the server, it functions as expected.

A test project is attached that exhibits this behaviour.

NetworkVariableErrorProject.zip

To Reproduce Steps to reproduce the behavior:

  1. Download the test project and extract it to two locations, one for the client and one for the server.
  2. Open the server project and open the scene named 'ServerScene'.
  3. Open the client project and open the scene named 'ClientScene'.
  4. In the server project, go to "Window -> Host Testing" and keep the editor window accessible during the test.
  5. Run both projects.
  6. In the server scene, click the 'Start Server' button.
  7. In the client scene, enter a player name, local IP and a simple string for the player GUID. ("aaa" is recommended).
  8. In the client scene, click the 'Login' button.
  9. The client should now be connected to the server. In the client scene, click the 'Continue' button to start the game.
  10. In the server scene, enter an integer value into the 'Winning Player ID' box and then click the 'Update Clients' button. Observe that the value is changing on the client. Repeat this a few times.
  11. In the server editor, in the 'HostNetworkTestingWindow', click the 'Disconnect' button to disconnect the client from the game.
  12. In the client scene, you will be disconnected from the server and the login screen will appear. Make sure the login details are the same as the first time you connected, and click the 'Login' button.
  13. In the server scene, make changes to the 'Winning Player ID' as you did in step 10, but observe that values aren't changing on the client.

Actual outcome The value on the client is correct on reconnection, but any further updates to that value are not received from the server.

Expected outcome When the server changes the value, it should change on the reconnected client as well.

Screenshots Attached is a screenshot showing the warning message mentioned in 'Describe the bug'.

warning_and_incorrect_network_object

Environment (please complete the following information):

  • OS: Windows 10
  • Unity Version: 2021.1.13f1
  • Netcode Version: 1.0.0-pre.3
  • Netcode Commit: e.g. https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/commit/bce722caef67190c568115caf69cc994bbab5836

Additional context It's worth noting that the NetworkObject that the offending NetworkBehaviour/NetworkVariable is on does not look correct for runtime in the editor after the client reconnects. So this may actually be a problem with the NetworkObject rather than the NetworkVariable. This is shown in the attached screenshot titled 'warning_and_incorrect_network_object'.

ben-magicn avatar Dec 15 '21 11:12 ben-magicn

Added this to our backlog (MTT-1967)

will-mearns avatar Dec 15 '21 16:12 will-mearns

Another finding I'd like to add is that if the client scene is reloaded on disconnect, and then the client reconnects to the game, it appears to function as expected.

ben-magicn avatar Dec 16 '21 16:12 ben-magicn

Still happening in 1.0.0-pre.4, the network variable is not synced with the value set with the server upon client connect. At least with FixedString32Bytes

CosmicStud avatar Jan 24 '22 23:01 CosmicStud

Still happening in 1.0.0-pre.4, the network variable is not synced with the value set with the server upon client connect. At least with FixedString32Bytes

I experience the same as well, and not just for FixedString32Bytes, pretty much all network variables. If I'm not mistaken, I believe on the reconnected client, the NetworkObject behavior on the offending game object is not set to "spawned", so nothing gets synced.

TheCaveOfWonders avatar Jan 26 '22 07:01 TheCaveOfWonders

Still happening in Netcode pre6, is there any news on this issue ? Thanks!

NaolShow avatar Mar 05 '22 12:03 NaolShow

happening to me when the player first joins...

In the lobby they all see each other, everything is fine.

In the game scene, after they all finish to connect to the scene, I try to spawn each player:

(on the server) public void SpawnPlayers(NetworkObject PlayerObject) { foreach (var Item in PlayerList) { ulong Id = Item.Key; NetworkObject NewPlayer; NewPlayer = Instantiate(PlayerObject, new Vector3((float)NetworkManager.Singleton.LocalClientId, 3f, 0f), Quaternion.identity); NewPlayer.SpawnAsPlayerObject(Id); } }

and I get the warning [Netcode] Deferred messages were received for NetworkObject #4, but it did not spawn within 1 second.

Any solutions?

theyonatan avatar Mar 14 '22 16:03 theyonatan

temp fix is to call it manually: ` void Awake()

{

    sunRotation.OnValueChanged += SunRotationChanged;

    SunRotationChanged(sunRotation.Value, sunRotation.Value);

}

`

Sneirox avatar Mar 19 '22 11:03 Sneirox

instancing after moving to a second scene seems to fix it for me. also try calling on Awake() instead of on Start() or could work with OnEnable();.

theyonatan avatar Dec 08 '22 18:12 theyonatan

Closing as the issue doesn't matter anymore as we removed the system it was part of ("Snapshots")

RikuTheFuffs avatar Jan 30 '23 16:01 RikuTheFuffs