Pre-populated SyncList and initial synchronization

Hi everyone. I’m using version 5.2.1f1. When a SyncList must pre-populated with a large number of items, is there any existing means to do that without using a loop and the Add operation?

If I needed to do that myself, I would go for something like the following. I noticed there was a public AddInternal method defined in SyncListStruct that you can use to bypass the sending of sync list message (it calls the internal list’s add method directly actually)… I’ll use that and send a single message handled on clients with the entire sync list serialized. Any caveat or other suggestions?

Curiously the already defined SyncListXXX classes seems to have static methods for serialization of an entire SyncList… I suppose this is used when other clients connect to the game to receive the entire sync list. Maybe that’s the thing…

This is bad design pattern. You will use enormous amounts of bandwidth and probably break the MTU limit for spawn messages.

What are you actually trying to do?

Hi seanr, you mean the single message thing right? It makes sense thanks.

I actually have a 3D grid of cells that needs to be completely synced once at the start of a game (about 5 bytes per cell at this stage and there are 8000 of them). This grid is auto-generated on server so it needs to be sent to clients before the game start.

Currently the synchronization is sending each cell separately in its own message (or so it seems). It doesn’t always work as it is in an inconsistent state for a short amount of time… how can I make sure the grid is completely received before spawning players and ennemies which need that grid?

Thinking further about your answer… did I mention that this step is done ONCE and subsequent modifications to the list will be synced via the SyncList implementation? That is, each time a cell is modified (and it won’t happen a lot actually) it sends a sync list message with SET or DIRTY operation (what’s the difference between the two by the way?) and the data itself. I did not meant to send the entire grid repeatedly. My problem was to send all data at the beginning with a minimum overhead and a somewhat “atomic” operation. It doesn’t need to be sent as a single packet though, and spawning is only done for some cells as the majority are empty.

I think there may be a way to pre-populate the list on both server and client (if the client knows what the default initial values are) and then if there is some way to SetDirtyBit to false so that all the initialization information isn’t sent? Something along those lines.

I have the same initialization efficiency issue as you. For example I have a SyncList for properties such as the size of a creature (since things can shrink/grow). Both the server and clients know the default size of the monster based on the prefab, say its 2.5 for ogres, and 1.2 for humans. Ideally I could set the SyncVar to the default value of 2.5 or 1.2 on both server and client, but not SetDirtyBit unless the value is set to something different than the default. However, in the current state I inefficiently send all initialization data over the network just as you do… :[

Zullar are you talking about SyncList or SyncVar actually?

SyncVar initial state are indeed sent the first time and I think you can do nothing about it… I may be wrong.

As for SyncList, I mentioned above that when you derive from SyncListStruct you have access to an AddInternal method to add elements to the list without messages being sent. So, my current idea is to fill the entire list with shared initial values for my cells on server and client using the AddInternal function, then, on server only, call the setter on cells that have different values. It will greatly limit the number of messages sent.

Ah that sounds perfect. AddInternal should work for you as long as it’s exactly matched on server and client.