Synchronize Server level with clients

    [Server]
    void InstantiateMap(){
        for (int b = 0; b < y; b++) {
            for( int a = 0; a < x; a++){
                GameObject toInstantiate = null;
                switch(mapData[a, b]){
                case 0:
                toInstantiate = ocean[Random.Range(0,ocean.Length)];
                break;
                case 2:
                toInstantiate = plain[Random.Range(0,ocean.Length)];
                break;
                case 3:
                toInstantiate = forest[Random.Range(0,ocean.Length)];
                break;
                case 4:
                toInstantiate = hill[Random.Range(0,ocean.Length)];
                break;
                case 5:
                toInstantiate = mountain[Random.Range(0,ocean.Length)];
                break;
                }

                Instantiate(toInstantiate, new Vector3(a, -b, 0), Quaternion.identity);
                NetworkServer.Spawn(toInstantiate);

            }
        }
    }

This is my code to instantiate a grid for a turn-based tactics game.

My problem is that despite the fact that I am spawning each and every tile, the map doesn’t show up in a test client; it’s all black.

How do I resolve this issue so the map appears when a client connects to the host?

Addenum, there’s a prior function that’s registering the prefabs in the clients:

    [Client]
    void RegisterPrefabs(){
        Debug.Log ("registering");
        for (int a = 0; a < ocean.Length; a++) {
            ClientScene.RegisterPrefab (ocean [a]);
        }
        for (int a = 0; a < plain.Length; a++) {
            ClientScene.RegisterPrefab (plain [a]);
        }
        for (int a = 0; a < forest.Length; a++) {
            ClientScene.RegisterPrefab (forest [a]);
        }
        for (int a = 0; a < hill.Length; a++) {
            ClientScene.RegisterPrefab (hill [a]);
        }
        for (int a = 0; a < mountain.Length; a++) {
            ClientScene.RegisterPrefab (mountain [a]);
        }
       
    }

i guess, could you need to use Network.Instantiate(.) ? try, maybe that might work. :slight_smile:

Problem solved. The prefabs were set to “server only”.

1 Like