Skip to content

changes to the NetworkList inside OnNetworkSpawn results in other clients not catching the change of the values #2163

@WarlordMSM

Description

@WarlordMSM

Description

After taking the steps below, clients do not get the updated value which was set on objects OnNetworkSpawn on server when the respective OnNetworkSpawn is called on clients. Only happens for NetworkLists and not NetworkVariables

Reproduce Steps

  1. make a basic networking scene with a default NetworkManager and a networkobject with this script attached to it.
  2. Make 3 buttons for calling "StartServer", "StartClient", and "RestartScene" methods from the script
  3. make a duplicate of the project(or use ParrelSync) or build the project to be able to test
  4. start the scene on both editors
  5. on one editor, call StartHost, and on the other, call StartClient (use UI buttons for convenience)

the rest of steps are required if the version is not 1.0.1 for the bug to happen:

  1. on the host, call RestartScene (use UI buttons for convenience)
  2. See error (also happens after step 3 on version 1.0.1)

Actual Outcome

The second Assertion("testList empty") fails and throws exception

Expected Outcome

all Assertions pass (no exceptions)

Environment

  • OS: Windows 10
  • Unity Version: 2022.1.12f1
  • Netcode Version: 1.0.0 and 1.0.1
  • Netcode Commit: NA (since used package manager and not Github)

Additional Context

  • I don't know about 1.0.1, but for 1.0.0, my guess is that because of the SceneManager's Sync call, the joining client gets the updated version of NetworkVariables and NetworkLists, while on restart, it does not happen, so the client that loads the game after the server, either because they still did not have the scene loaded or any other reason, misses the fields update call and does not also sync.
  • It could be also related the fact when spawn is called on server, the clients are still loading the scene.
  • Just as a note, if the code change to a owner-based logic, the expected outcome makes sense since the Spawn call on server(non-owner) is called sooner than the spawn call of the owner. But it would also fail on the first Assertion.
  • If OnNetworkSpawn is not a safe place to write/read NetworkVariables/Lists, the users of the library need another event/method that make it safe to read values especially in case of owner-based logic in which spawn on server is called before the owners spawn.
  • if the previous option is not possible, or just as a complement, it would be good for the users of the library to call a method on NetworkVariables/Lists that what it does is it tries to get the current value on server/owner (this method should be called on clients/non-owners)
  • a unitypackage of the scene setup is attached but I am not sure how it handles linking scripts from packages:
    NetworkListSyncIssue.zip

Metadata

Metadata

Assignees

Labels

priority:mediumThis issue has medium priority and may take some time to be resolvedstat:importedStatus - Issue is tracked internally at Unitytype:bugBug Report

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions