Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

PlayerObjects are only spawned on the Server correctly - all Clients only instantiate themselves.

Discussion in 'Multiplayer' started by CarterG81, Jul 3, 2015.

  1. CarterG81

    CarterG81

    Joined:
    Jul 25, 2013
    Posts:
    1,773
    What am I doing wrong?

    Code (csharp):
    1.  
    2. //Button UI on the Client calls a function that does this:
    3.  
    4. ClientScene.AddPlayer(0);
    5.  
    6.  
    Code (csharp):
    1.  
    2. //on my custom NetworkManager
    3.  
    4. public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId) //,
    5.    {
    6.      GameObject player = (GameObject)Instantiate(playerPrefab, Vector3.zero, Quaternion.identity); //Create the playerPrefab
    7.      NetworkServer.AddPlayerForConnection(conn, player, playerControllerId); //Spawn on Server & Ready
    8.    }
    9.  
    edit: Didn't know which is better, forum post or ANSWERS.
     
    Last edited: Jul 3, 2015
  2. Necromantic

    Necromantic

    Joined:
    Feb 11, 2013
    Posts:
    116
    What do you mean with see anyway? Are they not spawned or are they just not visible?

    Is the Prefab registered? Either via the NetworkManager property or ClientScene.RegisterPrefab?

    I had a similar thing happen once but don't remember what it was anymore.
     
    Last edited: Jul 3, 2015
  3. CarterG81

    CarterG81

    Joined:
    Jul 25, 2013
    Posts:
    1,773
    The playerPrefab is registered.

    The playerPrefab are not even instantiated on the Client. It's not like the renderer is hidden. The editor hierarchy shows no gameobjects at all besides the Client's own playerPrefab.

    In the build, the client works fine. In the UnityEditor though, once I start the client (OnStartClient), it makes all instantiated objects from OnStartClient (I instantiate a local non-network object and a GUIcanvasObject) disabled. Not sure why it does that, since they are non-network objects. I assume it is because it is not set as ready? What's weird is it only happens in the Editor, not in the build (which works normally and displays the GUIcanvasObject).

    The GUIcanvasObject holds the buttons and script which calls ClientScene.AddPlayer(0). Just basic UI Buttons.
     
    Last edited: Jul 4, 2015
  4. DrHeinous

    DrHeinous

    Joined:
    Jun 25, 2013
    Posts:
    19
    Same problem. On the host both the host player and player 'A' show. Player 'A' only shows 'A'. If 'B' joins, it appears on the host and on 'A'. But 'B' only sees 'B'.

    A possibly related problem is that I cannot seem to cause scene objects to spawn other than on the server/host. There they appear fine. On all clients I get 'spawn scene object not found for X'. Multiple different prefabs, all definitely in the networkmanager's prefab list. Or registered through code; no differenct.

    I have a sneaking suspicion these are part of the same problem, but I can't figure out what. Players join the scene in progress, they're all ready, etc. I'm really quite stumped at this point. This seems like it should be easy... but it just doesn't work.
     
    CarterG81 likes this.