Best way to Instantiate and synchronize 300 000+ GameObjects over LAN?

Hi, I completely new to Unity (couple of days) and I made a simple game with a map containing plenty of Sprites (2 types).
I want the game to be played on computers through LAN and I did network discovery of hosts/broadcast of server and synchronizing players positions.

Now I need to figure out how synchronize the map; both client and server have all assets. First how to “transfer” the map created by server to clients - should I use FOR I IN RANGE(0,300000){Network.Instantiate();} or that would be slow? Or should I send this map as an array through System.Net.Socket and create TCP socket for that manually - that would be very fast actually, but I want to know how fast/slow is Network.Instantiate, as I would use it for convenience.

Also, some sprites get destroyed, let’s say 40/second on average, so should I do Network.Destroy(GameObject)? Or again send an array with the destroyed GameObjects, but how? Can I send directly a GameObject? or just position, or what? How the other computer can know which GameObject to destroy based on e.g. position? It needs to be fast, too.
Thanks for your advice.

Ohhhh … wow…

I am not sure how simple game and 300 000 network instantiations can work together but okeee…

I don’t think you should use Network.Instantiate. It should be used for Players or Object taht must be synchronized and Instantiatet in runtime.

The idea with the TCP Sockets might be the best but I think it isn’t … let’s say… sexy… if you also use the Unity Networking. I wouldn’t mix them.
Perhaps you can serialize your map to a string and send this string over network (perhaps as a RPC call - not sur if this is best option - depending on the size of the final string).
It all depands on the kind of map you have. If ist is only a “binary map” it would be easier. So every tile can be this sprite or another sprite. So you only must go thru your map and put them to a long binary … thing. This thing could be encoded as base64 and maybe you try some compression algos out.

One last thing. I don’t know how your map is built. Because you wrote about sprites I think it is a 2d-tile map.
Having 300 000 single sprites could end with performance issues. If they are in the same texture Unity can batch them to gether to give you an performance boost.

This doesn’t sound too hard, actually, assuming the clients already have the map or a way to generate it from a small set of configuration parameters. Definitely don’t use Network.Instantiate() for each tile.

Setup

Use Network.Instantiate() to create a single network manager object that will contain your management RPCs.

Map Creation

Have the server call a single RPC to give the map to the clients. Instead of sending 300,000 tiles worth of data, instead just send the name of the map file to load or, if you are making the map procedurally at runtime, send the random seed and identifier of the algorithm used to create the map. Then create the map just as you would on the server (without using Network.Instantiate()).

Destruction

Call another RPC each time you want to destroy a tile, passing its identifier or coordinates. Then find the tile using the parameters and use Object.Destroy() instead of Network.Destroy().

You could also create new tiles on the fly using a third RPC.

Bulk Data

40 destruction RPC calls a second might not be too bad, but you could always record the destruction and then send them out in a bulk RPC call. To send a lot or variable amount of data in an RPC use this technique:

It could also be used to send all your map data if there is no way to generate the map on the client without sending info on all tiles.