Search Unity

How to create basic multiplayer without NetworkManager

Discussion in 'Multiplayer' started by coldzik, Jul 5, 2015.

  1. coldzik

    coldzik

    Joined:
    Jan 2, 2013
    Posts:
    12
    Like in topic.
    Does anyone have any tutorial of multiplayer without using network manager? Connecting client to server work, but spawning objects via NetworkServer.Spawn not working :(
    I must do something more like this?
    - Starting server
    - Connecting Client 1 do server
    - Send ready message to server
    - Server set client ready
    - Client call NetworkServer.Spawn
    - Client 2 Connecting
    - Send ready message to server
    - Server set client 2 to ready
    - Client call NetworkServer.Spawn
    - Clients doesn't see spawned objects (NetworkServer.Spawn)
    - Ofc spawned objects have Network Identity and Network Transform components
     
  2. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160
    "Send ready message to server" If you ever find how to do that, please let me know...

    I can see those two :

    NetworkServer.RegisterHandler(MsgType.Ready, OnClientReady);
    NetworkServer.RegisterHandler(MsgType.AddPlayer, OnAddPlayer);

    But the documentation says to use ; ClientScene.Ready () ... unfortunatly, nothing i put in there seems to work.
    IE :
    ClientScene.Ready(NetworkConnection 0) ;
    ClientScene.Ready(0) ;
    ClientScene.Ready() ;
     
    Last edited: Jul 6, 2015
  3. Kristonitas

    Kristonitas

    Joined:
    Jan 16, 2013
    Posts:
    9
    Maybe this helps:

    Code (CSharp):
    1.     public override void OnClientConnect (NetworkConnection conn)
    2.     {
    3.         base.OnServerConnect (conn);
    4.         myConnection = conn;
    5.         if (NetworkServer.active) {
    6.             GameObject.Find ("StatusLabel").GetComponentInChildren<Text>().text = "Am server";
    7.             ClientScene.Ready (conn);
    8.             connected = true;
    9.             ClientScene.AddPlayer (0);
    10.         }
    11.         else
    12.         {
    13.             GameObject.Find ("StatusLabel").GetComponentInChildren<Text>().text = "Am client";
    14.             ClientScene.Ready (conn);
    15.             connected = true;
    16.             ClientScene.AddPlayer (1);
    17.         }
    18.     }
    I use this code to automatically make clients that connect to server ready, and spawn player prefabs (something that stopped working when I connected to servers not using the default networkManagerGUI)
     
  4. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160
    @coldzik @Vazix

    I got the the "preliminary steps" working with a homemade networkmanager. Server Starts, remote client connects, sends the ready and spawn its playerprefab.
    The issue now stands in the fact that nothing happen on the localscene, or localclient...
    The remote client spawns its playerprefab but the host does not see it, even though it is the host who said which one to take... so all that does not really make any sens, and there is pretty much nothing in the documentation regarding the "localScene" on the host...
    Same for the localclient... it connects, and i am guessing it creates the playerprefab, but the localscene int he editor does not see that...
    If you guys have any idea / progress on your homemade network manager... pls let me know..
     
  5. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    I haven't tried it, but shouldn't you use NetworkServer.Spawn on the server? If you call it on a client I would expect nothing.
     
  6. Royall

    Royall

    Joined:
    Jun 15, 2013
    Posts:
    121
    The client should not call NetworkServer.Spawn...
    And did you register the spawnable prefab on the client?

    Code (CSharp):
    1. ClientScene.RegisterPrefab(GetComponent<Controller>().playerPrefab);
    2.            
    3.             myClient.RegisterHandler(MsgType.Connect, OnClientConnected);
    4.            
    5.             myClient.Connect("127.0.0.1", 7070);