- Home /
Transferring procedural map to clients
I am working on a simple multiplayer game that uses a map generated by the server. How can I transfer the map to clients when they join? The map data is an array of heights, currently float[]
, and about 300,000 points (approx 1.2MB). The map is generated from information only available on the server, so I cant just send a seed and re-generate the map on the client. The absolute minimum would be packing the data for two points into a byte
, for a total of 150kB.
I have tried using a ClientRpc
to send the data, but that freezes the editor when it is the server, and causes an out of memory error when a (32 bit) standalone build is the server. The standalone server normally uses just over 150MB of RAM, so the RPC is adding at least another 2GB. Further testing revealed a limit somewhere between 5000 and 10000 elements in the array
[ClientRpc]
public void RpcUpdateTerrain(float[] heights) {
Debug.LogError("Got heights, len: " + heights.Length);
}
What is the recommended way for transferring the map data?
Answer by Bunny83 · Oct 12, 2017 at 02:28 AM
Well, RPCs (remote procedure calls) aren't ment to submit a large amount of data. However i don't see a reason why it shouldn't work. Obviously that amount of data doesn't fit into a single packet so it has to be splited into several packets.
One solution might be to send the data in several smaller chunks. Depending on the nature of those values you might be able to use some sort of delta compression. Apart from that any kind of compression would of course help to reduce the amount of data you have to send.
I doubt that 1.2MB of data can cause an out of memory exception. You may do something wrong, somewhere which might cause this problem.
Keep in mind that any kind of network game should have runInBackground set to true.
Is there a way to check how many slots are left in the send queue? When I switched to sending it in chunks, I got errors and warnings about dropped packets.(I'll check what the actual error was tomorrow) After setting the chunk size low enough that the errors stopped (500/frame), it takes much longer than I'd like to send.
I'm not sure if something else is contributing to the OO$$anonymous$$ exception, but just switching from sending new float[10000]
to the actual array caused it.
With the array size set at 5000, I got two logs no free events for message in the queue
, two errors Failed to send internal buffer channel:1 bytesToSend:16
, an error ChannelBuffer buffer limit of 16 packets reached.
, and a warning ChannelBuffer recovered from overflow but data was lost.
Your answer
Follow this Question
Related Questions
What is the maximum feasible number of players in a procedural-generated, top-down 2D MMO? 1 Answer
Unity Multiplayer Design. Is it complicated to implement and learn? 1 Answer
Code Wont Work? 0 Answers
Questions about Multiplayer and Networking? 1 Answer
What do I need to implement web-server for multiplayer without Unity services? 2 Answers