Search Unity

Having players in multiple scenes at once.

Discussion in 'Multiplayer' started by Demozo, Jul 20, 2015.

  1. Demozo

    Demozo

    Joined:
    Aug 19, 2014
    Posts:
    20
    The title says most of the story, really.

    What I'm trying to achieve is having a staged login system (Main menu -> Login -> Character Selection -> Game). Is it even possible to do this?
    I thought of having the player log in offline via a WWWForm object but then the game server wouldn't know about the player having actually logged in, but connecting to the server first and then sending a WWWForm to the server which tells the player "OK" or "No" isn't possible either because the client gets sent to the online scene automagically.
    It is actually possible to do it like that but then character selection and login would have to be in the actual game scene as well which is not a proper way of doing things in my opinion.
     
  2. Disastorm

    Disastorm

    Joined:
    Jun 16, 2013
    Posts:
    132
    I'm trying to figure out the same thing, to no luck.

    I did find out something that almost works.

    I have it so after the player connects, before sending "Ready" to thes erver, it loads a character creation/select Scene. he selects the char and sends the data to the server and then loads the main scene and tells the server hes ready, and then the server will spawn the player prefab.
    I've gotten this to work except for the player prefab that is spawning is not correct, but I think that is an issue in my logic somewhere.
    However, there is one thing wrong is that after connecting, the client automatically loads the main scene "automagically" as you mentioned, even before he sends "Ready", thus the client ends up loading the main scene, then loading the char scene, then back to the main scene again. As far as I've seen there is no way to prevent the main scene from loading on client connection, but a possible workaround is to Mask a black screen or a loading image over the game so that the user doesn't see the main scene before the select scene.

    *edit looks like this version doesn't work as well as I thought as it looks like predefined scene networkentities aren't connected properly when you load levels in the middle of being connected.
     
    Last edited: Jul 21, 2015
  3. Disastorm

    Disastorm

    Joined:
    Jun 16, 2013
    Posts:
    132
    I discovered a decent solution although its not the best.

    You can design your Character Selection scene separately and then load it into the main scene with LoadLevelAdditive()

    After you are done with the Character Creation/Selection you can then Destroy the scene ( put the whole Char Creation scene in a single parent object so you can just destroy it with that ). It seems to work pretty well, although of course its still a bit weird since you are putting it into the main scene, but from a user perspective it looks perfectly normal.
     
  4. Demozo

    Demozo

    Joined:
    Aug 19, 2014
    Posts:
    20
    Are you still preventing the "Ready" status from being sent with this solution?
     
  5. Disastorm

    Disastorm

    Joined:
    Jun 16, 2013
    Posts:
    132
    Yes.
    Actually i completely removed the Ready status because for some reason when I was calling it, it was saying the client is already Ready, so there may be some kind of bug there.
    However, the main thing is that I'm not calling

    ClientScene.AddPlayer(0);

    until after character creation. Originally I had it as

    ClientScene.Ready(NetworkManager.singleton.client.connection);
    ClientScene.AddPlayer(0);

    But as I mentioned, it was claiming it was already ready so I commented out the Ready line. I'm not really sure about that, perhaps it has something to do with the singleton client connection.
     
  6. Demozo

    Demozo

    Joined:
    Aug 19, 2014
    Posts:
    20
    So if I get this right, you connect to the server, you login, select/create a character and then destroy the character selection/creation scene from the main scene? And ClientScene.AddPlayer(0); is responsible for spawning the player?
     
  7. Disastorm

    Disastorm

    Joined:
    Jun 16, 2013
    Posts:
    132
    yes thats what it seems like. Not sure why ClientScene.Ready isn't needed.
    You also need the spawning code in the Server-side callback OnServerAddPlayer, that is also the place where you will decide how you spawn your game object based on your character creation/selection.

    For example, I'm storing the player's created character in memory (serialized Unity Multipurpose Avatar) and when the OnServerAddPlayer gets called, the server creates a Unity Multipurpose Avatar Dynamic Avatar and populates it with the serialized character creation data.


    There is one issue with the Character Creation is that when spawning it with LoadLevelAdditive, the Canvas got messed up. There may be a way to fix it but for now I set it to Camera space instead of Overlay, and that fixed it, but unfortunately puts in in the Camera space so depending on the angle, certain parts of my avatar can actually go in front of the Canvas.
     
  8. Demozo

    Demozo

    Joined:
    Aug 19, 2014
    Posts:
    20
    Thanks! I'll see if I can get it to work now.