SyncList

I’ve got a list with my players and a small amount of data for them each that I want to send to the clients.

Is there a chance that some wonderful person might be able to show me how to do a SyncList?

I second this request - I’ve been trying to figure out how to use them, but haven’t had much luck on my own. I keep getting initialisation errors on my clients when they try to use my SyncList.

I presume this can be used for scores etc? I’m also interested in this.

I’ve since figured out how to handle them. The documentation is located here: http://docs.unity3d.com/Manual/UNetStateSync.html

If you guys want a practical example, take a look at this thread (one of the answers is a chat system where the SyncListString type is used) :slight_smile:

https://www.reddit.com/r/Unity3D/comments/3bbk1y/help_with_unity_networking/

I am now doing precisely that RSH1 - although I found for my needs I didn’t even need a SyncListString, I am using a very simple string with a SyncVar attribute to keep all my scores sync’ed across player clients. I separate scores with a carriage return and simply parse them out of the string if I need to single one out and modify a particular player’s score entry. The carriage return is my delimiter. But a SyncListString would be a good choice in my opinion.

Another thing you guys might find useful is serializing the list into a byte array and sending it via message. I have a player list that I need to be synced but I wanted to do that outside of a NetworkBehaviour. That’s why I do this:

ByteMessage msg = new ByteMessage (); //ByteMessage is derived from MessageBase and contains a byte array
        msg.bytes = GameUtilities.ToByteArray (players); // this converts the player list to a byte array
        NetworkServer.SendToAll((short)ClientMessages.ReceivePlayerList, msg); //This sends the message

Then upon receive, the clients filter out the local properties and sync the global ones.

I hope this helps. I’m still figuring out UNET so there might be a better way to do this outside a NetworkBehaviour if somebody knows one, please do share.

1 Like

Nice idea Dark Protocol - I’ve not gone further than using the convenience attributes and standard UNET stuff yet, but this looks like a nice idea to take it further.

1 Like

Thanks, I did run however into a problem with that a few minutes ago. My player list holds a lot of information and if it gets bigger (more players join) Unity would throw out an error stating that the message is too big to be transfered so that would be one thing to watch out for with this method. I’m trying to figure out how to use a custom channel to send the player list with. There is SendByChannelToAll in NetworkServer but you can’t send by a channel to a specific client from what I’ve seen so far.

NetworkConnection class has a SendByChannel method or a Send method which takes channel. Use a Fragmented channel for big messages. If you are not using NetworkManager to add channels there then a ConnectionConfig should be used for both server and client with NetworkServer.Configure(configChannel,maxplayers) and NetworkClient.Configure similarly.