Search Unity

Ghostly Connections? [Solved]

Discussion in 'Multiplayer' started by Flynn, Oct 23, 2009.

  1. Flynn

    Flynn

    Joined:
    May 24, 2009
    Posts:
    311
    For whatever reason, Network.connections.length, is always returning zero! Even when I (The host of a server) have successfully connected to my game!


    Same luck with Network.connections.Length...


    I need the for a function in my script - Players have all ready connected, and are made to wait to be spawned... Likewise, instead of being spawned on join, I have a script iterate through the array of connections, instantiate an object, and assign the object to the player that it was instantiated for.


    Here is my code:

    Code (csharp):
    1. @RPC
    2. function loadplayers()
    3. {
    4. cons = Network.connections;
    5. Debug.Log("Hello?" + cons.Length);
    6. for (i = 0; i < cons.Length; i++)
    7. {
    8.     var pos : Vector3;
    9.     pos = transform.position;
    10.     var clone = Network.Instantiate(playerPrefab, pos, transform.rotation, 0);
    11.     var script1 : datan;
    12.     script1 = clone.GetComponent(datan).child.GetComponent(datan);
    13.     script1.spawn = transform;
    14.     script1.GetComponent(NetworkView).owner = cons[i];
    15.     Debug.Log(Network.connections.length);
    16.     con = Network.connections.length;
    17. }
    18. }
    Oh, and though there is a "@RPC" up there, I am not calling the function with an RPC yet, I want to get the function working first.


    I also have another snippet of code, in my Update function.

    Debug.Log(Application.loadedLevel +":::"+ Network.connections.length);

    I've tried both length, and Length, with the same result.

    Finally, I've tried loading data from Network.connections[0].ipAddress, causing the script to stop working at that point.


    It's as if I don't exist to the server, when I'm perfectly connected! :?
     
  2. Flynn

    Flynn

    Joined:
    May 24, 2009
    Posts:
    311
    Well, it looks like network.connections only includes people who join a sever. (Go figure.)


    I'd like to get all the NetworkPlayers in the scene, including the host.... How might I do this?

    (I'm working on that right now...)
     
  3. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    hmm interesting, so you want to know how many players are in the view frustum or the scene/level in general? network.connections gives you all players attached to the server instance which can house many levels

    you probably have to handle this on your own since the network interface has no information about your levels or your scenes
     
  4. Flynn

    Flynn

    Joined:
    May 24, 2009
    Posts:
    311
    Ahh, I forgot to post an update on this post - I remembered a way of getting all the players in my scene.

    Thanks for your input, zumwalt!