After latest update (738047) - Networking: SyncLists now only send updates when values change
the behaviour of SyncList has been changed.
Callback function is calling before internal buffer is updated now.
I’m always getting previous value and not sure that it is correct behaviour.
What is your code? (With comments, so I can read clearly.)
I hope this example is clear enough.
Values are always different
StartCoroutine() is only run once. When it is called, it will execute from where it left off. For more info, please read Coroutines.
Put StartCoroutine() function call in Update() and check again.
When you put StartCoroutine in Update it’ll be called on every single frame, also that function never ends, it’s infinite loop with 2sec interval.
Don’t have Unity running right now, but maybe you can try removing the loop and use InvokeRepeating(“Updater”, 2f,2f)
that Updater function is running on the client?? it should only run on the server
Thanks to all for participating
Coroutine is not a problem at all and works as expected. It was used only for decreasing amount of debug outputs.
For this particular example I used NetworkManager as a Host ( client and server in one process), because the problem is easy reproducible. Believe me, you will get the same problem if you will split the code for client and server parts.
Okay, I could see where you’re getting at. Bear with my handwriting, for I have a crappy, 8 years old drawing tablet.
This is what you have at the moment:
To fix this issue, you need to mark your variables dirty.
IEnumerator Updater() {
while (true) {
counter++;
CmdUpdateValue(counter);
this.list.Dirty(0); //<---- Mark it dirty prior to being called. The "0" is the index.
Debug.Log("SyncList internal: " + list[0]);
yield return new WaitForSeconds(2f);
}
}
And this is what happens after:
The extra Synclist callback log message is due to “OnListChanged” callback event you have set, since it’s being updated.
That is what you need to do. Good luck.
Thank you for your reply. As you correctly noticed I will get twice notification in this case - one incorrect, and second correct. This is not acceptable for me.
My intention of this post was to get attention of unity developers. From my point of view this is a bug.
Well, by all means, report your findings to Unity via the toolbar menu, Help → “Report a Bug…” in the editor. Let them decide what to do in your case.
Can confirm, this is an old bug that was fixed a few weeks ago but reintroduced lately. I also reported it here: BUG: Old SyncList Callback bug was reintroduced to 5.3.3f1 - Unity Engine - Unity Discussions
Yes, the behaviour has changed and I can see the issue myself here, sorry about that, this is a regression so has high priority and I’m working towards getting the fix into next patch release. If you have a bug ID for this send it to me so I can attach it to the fix (if not I’ll just create on myself). Thanks for brining this up and providing the clear repro.
Yeah. I finally ran into this problem myself. I had been populating my SyncLists AFTER spawning players. However, now that my database is up and running, I populate a player’s inventory (SyncListStruct) before calling NetworkServer.AddPlayerForConnection(). I’m running 5.3.2f1 Personal…and the server has the correctly populated SyncListStruct upon spawning the player, but the client’s SyncList is empty.
Thank you for your response. Case 774970 was created by me.
This might be another bug that I encountered too: http://forum.unity3d.com/threads/unet-bug-when-modifying-syncliststructs-before-addplayerforconnection.381606/
If you use a filename that UNET doesn’t like, then the synclists aren’t properly synced to the clients. I noticed that when populating them after AddPlayerForConnection, they will be send to the client but only to that client, not to all the other clients around him. And if you populate them before AddPlayerForConnection then they aren’t sent to any client. Unless you rename the file name, then everything works.
Hmmm. Seeing the different file names you used, I don’t see a pattern, so I don’t think that’s the actual cause.
Hmmmm, looks like I’m somewhat affected, even though I already made use of codes. I guess I have some hacky workarounds?
Well there’s only 2 ways you’ll be affected (it seems like).
- You need to be making use of the SyncList callback.
- You need to populate a SyncList before the GameObject is spawned.
And of course you need to be running 5.3.2 or higher.
I am populating my SyncLists, but I used delegates to work around this. So, I guess I’m not entirely affected. Thanks though.
So you’re doing:
- Instantiate()
- SyncList.Add()
- NetworkServer.Spawn()
In that order?