Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Why won't this basic Unet example connect?

Discussion in 'UNet' started by gsus725, Jul 29, 2017.

  1. gsus725

    gsus725

    Joined:
    Aug 23, 2010
    Posts:
    250
    EDIT: Wow it was the latest Beta stopping it from working. It works fine in 5.3.5.

    Following this simple example: https://docs.unity3d.com/Manual/UNetClientServer.html I'm supposed to get a Connect message from just this code. I run 2 instances of the game and the server starts, so I try to connect with the other instance and...nothing happens! It continues printing every frame "client.isConnected = False". My pc is port forwarded, and the scene is just 1 empty game object with this script attached. Why can't the client connect?

    Does UNET not work in the latest Unity Beta Free Version? Do I need a NetworkIdentity somewhere?

    Code (JavaScript):
    1. import UnityEngine.Networking;
    2.  
    3. private var client : NetworkClient;
    4.  
    5. function Update(){
    6.  
    7.     if(client) print(client.isConnected);
    8.  
    9.     //be server
    10.     if(Input.GetKeyDown(KeyCode.S)){
    11.         NetworkServer.Listen(7777);
    12.     }
    13.  
    14.     //be client
    15.     if(Input.GetKeyDown(KeyCode.C)){
    16.         client = new NetworkClient();
    17.         client.RegisterHandler(MsgType.Connect, ClientConnect);
    18.         client.Connect("127.0.0.1", 7777);
    19.     }
    20. }
    21.  
    22. function ClientConnect(n : NetworkMessage){
    23.     print("ClientConnect");
    24. }
     
    Last edited: Jul 29, 2017