Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Multiple local players joining online game

Discussion in 'Multiplayer' started by BortStudios, Aug 17, 2015.

  1. BortStudios

    BortStudios

    Joined:
    May 1, 2012
    Posts:
    48
    I cannot figure out how to do this. Currently what I am wanting to do is as follows: I have a screen where player 1 can pick a character and customize it, and three others can press A to join and customize their own characters. When they are all ready, these four character customizations host or join a server, where playerobjects are spawned for them and their customization options are applied to their playerobjects.

    That is, the players all join, and then they are added to the server. When I try to use ClientScene.addplayer, though, it says I need a connection. Do I need to already be hosting or joining a server to add multiple local players?

    Thanks
     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
  3. BortStudios

    BortStudios

    Joined:
    May 1, 2012
    Posts:
    48
    I understand the concept of transferring data between scenes - it's the multiple local players going online that has me confused. If the sample project has that feature, I cannot find it.
     
  4. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
  5. BortStudios

    BortStudios

    Joined:
    May 1, 2012
    Posts:
    48
    I really cannot see how the hook has anything to do with multiple local players joining an online match. It looks like it is only for transferring traits from a lobby prefab to an in game prefab?
     
  6. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    The flow for the NetworkLobby is:
    • Start a Host
    • Add a LobbyPlayer object for each player, using ClientScene.AddPlayer() (for example, this can driven by pressing controller buttons for local players)
    • Remote players can also connect at this time and add players
    • every hits their "ready" button
    • The game switches to the game-play scene
    • OnLobbyServerSceneLoadedForPlayer is called on the server for each player (local and remote)
    The existing NetworkLobby doesn't really support joining games in progress, it requires everyone to be in the lobby when the game starts. The regular NetworkManager supports join-in-progress though.
     
  7. BortStudios

    BortStudios

    Joined:
    May 1, 2012
    Posts:
    48
    Ah, okay. I did notice that AddPlayer() requires an established connection, which is why you starthost first. But what if I want to have a party of local players join as a client? Can I have everybody locally join, and then have that party join a game hosted elsewhere?

    [EDIT]

    I am using a standard NetworkManager, too, implementing a custom lobby system instead
     
    Last edited: Aug 17, 2015
  8. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    There is nothing built-in to the NetworkManager to do that. You'd just have to have them all join the remote game and call AddPlayer() once a connection was made to it. So there would be a local, offline, "Pre-lobby"? Probably the same thing would work for both local and remote games.
     
  9. BortStudios

    BortStudios

    Joined:
    May 1, 2012
    Posts:
    48
    Thanks. Okay, I have the server creating the correct number of players. But how do I transfer the data from the client scene to the server scene? I have the client call AddPlayer() for each local player, but the server at that point doesn't know what options the client had select when it's creating its player with AddPlayerForConnection().

    [edit]
    I guess I should just change my code so that the items the players select are stored by string and then can be synced to the server, rather than stored by reference
     
    Last edited: Aug 18, 2015
  10. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    One the players are connected to the server, they can send commands to choose their items. If the items are SyncVars or SyncLists on the server, then other players (even remote ones) will see the item choices of the players.