Sending/Recieving map data

Hello there.

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.

Would apreciate any help !

Thanks alot !

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

Thanks alot for the attention !

This is my lastest test so far, ive tryed using this BufferedRPC with no success at all…

I read many stuff about RPC but its not a clean concept yet.

This is my simple networkManager

using UnityEngine;
using System.Collections;

public class NetworkManager : MonoBehaviour
{
    private const string typeName = "NamelessDungeonCrawler";
    private const string gameName = "Random Dungeon";

    private bool isRefreshingHostList = false;
    private HostData[] hostList;

    public static NetworkManager handle;

    public GameObject playerPrefab;

    void Start()
    {
        handle = this;
    }

    void OnGUI()
    {
        if (!Network.isClient && !Network.isServer)
        {
            if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
                StartServer();

            if (GUI.Button(new Rect(100, 250, 250, 100), "Refresh Dungeons"))
                RefreshHostList();

            if (hostList != null)
            {
                for (int i = 0; i < hostList.Length; i++)
                {
                    if (GUI.Button(new Rect(400, 100 + (110 * i), 300, 100), hostList[i].gameName))
                        JoinServer(hostList[i]);
                }
            }
        }
    }

    private void StartServer()
    {
        Network.InitializeServer(5, 25000, !Network.HavePublicAddress());
        MasterServer.RegisterHost(typeName, gameName);
    }

    // i just starter a new dungeon
    void OnServerInitialized()
    {
        SpawnPlayer();
    }

    // ive entered an existing dungeon
    void OnConnectedToServer()
    {
        networkView.RPC("loadNetworkMap", RPCMode.OthersBuffered, DungeonManager.handle.generator.map);
        SpawnPlayer();
    }


    void Update()
    {
        if (isRefreshingHostList && MasterServer.PollHostList().Length > 0)
        { 
            isRefreshingHostList = false;
            hostList = MasterServer.PollHostList();
        }
    }

    private void RefreshHostList()
    {
        if (!isRefreshingHostList)
        {
            isRefreshingHostList = true;
            MasterServer.RequestHostList(typeName);
        }
    }

    void setupMap() {
    }

    [RPC]
    public void loadNetworkMap(int [,] map)
    {
        DungeonManager.handle.generator.map = map;
        Debug.Log("recieved a map being server = " + Network.isServer);
    }

    private void JoinServer(HostData hostData)
    {
        Network.Connect(hostData);
    }

    private void SpawnPlayer()
    {

        GameObject player = Network.Instantiate(playerPrefab, new Vector3(DungeonGenerator.initialPos.x, DungeonGenerator.initialPos.y, 0), Quaternion.identity, 0) as GameObject;
       
    }


}

So when a player joins, he needs to recieve the map so he can build the same map the host generated.

This is my first attempt to do an online game, so feel free to say if im going on the wrong way.

Thanks alot for any attention !

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.

Would someone be willing to write a new guide for this? The code** Zirokden** provided is already out-of-date.