Search Unity

Connecting Clients To Server's Level

Discussion in 'Multiplayer' started by GhostFrag1, Aug 31, 2014.

  1. GhostFrag1

    GhostFrag1

    Joined:
    Feb 9, 2014
    Posts:
    6
    I have been learning how to use Unity Networking and have been doing fairly well with it. One problem I am having is the Server Loading a scene then allowing the clients to connect to that scene. So far the server host chooses the Name, Port and Player amount and map for the server which the level is then loaded with Application.LoadLevel(Level Number). And I can't seem to find a way to connect the client's looking to join a server to actually join that same scene as the host. The client looking to join does connect as it is shown by the stats in the unity editor. Thanks for any help.
     
  2. welby

    welby

    Joined:
    Mar 22, 2011
    Posts:
    549
    I just recently got into the networking thing, but I'll give it a shot.

    make sure you are using that Application.LoadLevel inside an RPC function.

    Code (csharp):
    1.  
    2.     [RPC]
    3.     public void UpdateLevel( NetworkPlayer player, string levelName) {
    4.         Application.LoadLevel(levelName);
    5.     }

    and calling it with(example, "maingame" is my own scene name and that number 4 will be different for you, it refers to your unity scene)
    note the 'allbuffered' that's important for players who join later."

    Code (csharp):
    1. networkView.RPC( "LoadLevel", RPCMode.AllBuffered,"MainGame",4);
    2.  

    if you're still stuck,..

    I learned from these two tutorial series



    and




    good luck!
     
  3. GhostFrag1

    GhostFrag1

    Joined:
    Feb 9, 2014
    Posts:
    6
    Thanks for the help! Will be sure to try this ASAP. Thanks again.
     
  4. Cha0os

    Cha0os

    Joined:
    Feb 22, 2014
    Posts:
    17

    This doesn't really make sense. Why are there two parameters in the "UpdateLevel" function when you only use levelName? Also, why do you pass a string and an integer to a procedure that takes a NetworkPlayer and a string?

    I'm pretty sure you got your examples mixed up there and this may lead to some confusion.
     
  5. GhostFrag1

    GhostFrag1

    Joined:
    Feb 9, 2014
    Posts:
    6
    What would you recommend doing? I tried welby's code and that didn't work.
     
  6. welby

    welby

    Joined:
    Mar 22, 2011
    Posts:
    549
    whoops,.yeah,..sorry I posted the wrong RPC.

    this is what my RPC looks like for that call

    Code (csharp):
    1.  
    2.     [RPC]
    3.     void LoadLevel (string level, int levelPrefix)
    4.     {
    5.  
    6.         Application.LoadLevel(level);
    7.     }
    8.  

    'level' is the number of your scene( if you look in the build setting menu'
    I am not using the level prefix. still,..it is specific to my game,..you may be better off doing those youTube tuts on their own project first to get 'something' working, then pick apart what you need from that.

    Oh,....missing a step I think,..Clients need to connect to your server host Before any level loading is going on.

    something like this,.

    Code (csharp):
    1. Network.Connect(hostData[i]);
    2.  
    UNity Ref page


    once they connected,..then they can use the buffered load level to enter.

    again, though,..those youTube vids do a good job of explaining joining a server.
    I'm sorry,..I know this code snipping is spastic,.. :p
    good luck!
     
    Last edited: Sep 1, 2014