Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Synchronize Server level with clients

Discussion in 'Multiplayer' started by terabix, Sep 4, 2015.

  1. terabix

    terabix

    Joined:
    Jun 14, 2015
    Posts:
    5
    Code (CSharp):
    1.     [Server]
    2.     void InstantiateMap(){
    3.         for (int b = 0; b < y; b++) {
    4.             for( int a = 0; a < x; a++){
    5.                 GameObject toInstantiate = null;
    6.                 switch(mapData[a, b]){
    7.                 case 0:
    8.                 toInstantiate = ocean[Random.Range(0,ocean.Length)];
    9.                 break;
    10.                 case 2:
    11.                 toInstantiate = plain[Random.Range(0,ocean.Length)];
    12.                 break;
    13.                 case 3:
    14.                 toInstantiate = forest[Random.Range(0,ocean.Length)];
    15.                 break;
    16.                 case 4:
    17.                 toInstantiate = hill[Random.Range(0,ocean.Length)];
    18.                 break;
    19.                 case 5:
    20.                 toInstantiate = mountain[Random.Range(0,ocean.Length)];
    21.                 break;
    22.                 }
    23.  
    24.                 Instantiate(toInstantiate, new Vector3(a, -b, 0), Quaternion.identity);
    25.                 NetworkServer.Spawn(toInstantiate);
    26.  
    27.             }
    28.         }
    29.     }
    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?
     
    Last edited: Sep 4, 2015
  2. terabix

    terabix

    Joined:
    Jun 14, 2015
    Posts:
    5
    Addenum, there's a prior function that's registering the prefabs in the clients:

    Code (CSharp):
    1.     [Client]
    2.     void RegisterPrefabs(){
    3.         Debug.Log ("registering");
    4.         for (int a = 0; a < ocean.Length; a++) {
    5.             ClientScene.RegisterPrefab (ocean [a]);
    6.         }
    7.         for (int a = 0; a < plain.Length; a++) {
    8.             ClientScene.RegisterPrefab (plain [a]);
    9.         }
    10.         for (int a = 0; a < forest.Length; a++) {
    11.             ClientScene.RegisterPrefab (forest [a]);
    12.         }
    13.         for (int a = 0; a < hill.Length; a++) {
    14.             ClientScene.RegisterPrefab (hill [a]);
    15.         }
    16.         for (int a = 0; a < mountain.Length; a++) {
    17.             ClientScene.RegisterPrefab (mountain [a]);
    18.         }
    19.        
    20.     }
     
  3. arcady87

    arcady87

    Joined:
    Jul 24, 2013
    Posts:
    25
    i guess, could you need to use Network.Instantiate(.) ? try, maybe that might work. :)
     
  4. terabix

    terabix

    Joined:
    Jun 14, 2015
    Posts:
    5
    Problem solved. The prefabs were set to "server only".
     
    arcady87 likes this.