Im making a simple co-op dungeon crawler using unity standard network objects.
Ive managed to make player joining rooms/seeing other players movement etc, but the map is generated one time w/o a seed. So, when a second player joins, i wish to get the maparray in the other player map script (the map generates a map array indicating tiles) so it can build the map with that array, but im not sure how can i transfer this map array so the player who joined can create the map on his client.
It’s hard to tell without seeing some code, but an easy way of doing it would be sending a buffered RPC to all of the players so they automatically receive the map data upon joining.
If you have to store anything for all players who might join later on, use Custom Properties for the Room. Check out:
PhotonNetwork.room.SetCustomProperties();
A property’s value can be a byte[ ] which should be ok for your map.
Thanks for the reply. Im new to unity networking, ive tryed to send that BufferedRPC but as far as i can see RPC methods cannot return stuff. I dont use Photon btw im using unity master server.
I have a int [ ][ ] buildMapArray() and it stores in a variable in the script called mapArray. How could i send this to a player when he joins ? Im googlin it but im having trouble finding good material on unity networking
Well you are using the RPC in the wrong place, your server should create the map in OnServerInitialized and stores the array, Then send the RPC of LoadMap to others to load the map using its array as buffered RPC.
I’m not sure if multi dimentional arrays are supported in unity or not but if not then you should first make your array 1d as an int[ ] instead of in[,] and then send it in addition to its actual dimentions to recreate it in the other side.
Also just sending the seed should be good enough if the random generator only uses your seed.
About RPCs: They way that they work is that you send the name of an RPC method to someone and they’ll execute it with your sent parameters. In your current code every client will send it buffered to all other clients and server, so server will call the method N times where N is number of clients , All clients will do it as well.
The best alternative is uLink and UnityPark suite. API is similar to unity and much more powerful. take a look at www.muchdifferent.com and http://developer.muchdifferent.com just get the trial and take a look but for your first game and if it’s only a hobby, built in networking might be good enough. It depends on what you want to do.