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

NetworkManager not instantiating player prefab on reconnect

Discussion in 'Multiplayer' started by Reisender, Oct 7, 2015.

  1. Reisender

    Reisender

    Joined:
    Jun 26, 2014
    Posts:
    35
    I'm trying a very basic configuration for multiplayer games.

    I have a NetworkManager with no advanced configuration and a NetworkManagerHUD attached, and I'm trying this inside the editor in Unity 5.2.1f1:

    - Start the game.
    - Press "LAN Host"
    - Press "Client Ready"

    At this step, everything works fine and a player prefab is instantiated. But then:

    - Press Stop
    - Press "LAN Host"
    - Press "Client Ready"

    And now the player prefab won't be instantiated.

    This also happens when I try to reconnect from another device: I tried building and running in Android, then run in the Editor as Host and in Android as client. The first time the Android client connects everything works fine, but if he leaves and then tries to reconnect, its player object is not created.

    If I stop the editor and then start it again, it works once again, just for the first connection.

    Any ideas on how to solve this? Thanks!
     
  2. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Have you actually try spawning your player prefabs after you made your clients ready? As in, when you send signals saying clients are ready, you're just telling the server that the clients are ready, and nothing else. Anything happens after telling the server the clients are ready?
     
  3. _Adriaan

    _Adriaan

    Joined:
    Nov 12, 2009
    Posts:
    481
    Are there maybe two NetworkManagers in the scene?
     
  4. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    you shouldnt ever have to press the "Client Ready" button unless you have changed the NetworkManager default behaviour. Do you have custom NetworkManager code?
     
  5. Reisender

    Reisender

    Joined:
    Jun 26, 2014
    Posts:
    35
    Thank you all for your quick responses!

    I 've just uploaded this video to youtube to show you this behaviour:


    As you can see in this video:
    • I have only one NetworkManager with default behaviour.
    • For this example, my player prefab is just a cube with a network identity and Local Player Authority checked.
    • There's no way to continue to the game other than pressing "Client Ready".
    • The first time I press "Client Ready", the cube spawns in the correct position.
    • But then stopping it and creating the host again... and then pressing again "Client Ready", the cube no longer spawns.
    • Finally I stop the game, run it again and follow the same steps.
    I've not tried the solution proposed by asperatology (spawning player prefabs after I made my clients ready)... how would I achieve this?
     
  6. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    You filled in one of the NetworkManager scene slots but not the other?

    It appears that there is a bug when the online scene is set and the offline scene is NOT set, where the local client is not becoming ready. bug 734218 filed on this.

    to work-around this, either leave both slots empty or fill them both.
     
    Reisender likes this.
  7. Reisender

    Reisender

    Joined:
    Jun 26, 2014
    Posts:
    35
    That's it! In both cases works fine: either both filled or both empty.

    Thanks a lot!
     
  8. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Well, since it's a bug, let's continue discussion while they are working on a patch.

    By spawning prefabs, what you do is you call on NetworkServer.Spawn() or NetworkServer.SpawnWithClientAuthority() on the server side of your game. Here's more details.

    I am guessing it is also possible to spawn objects in the NetworkManager, when all the clients are telling the server that they are ready.