Search Unity

Connect to new scene server without loading scene on client

Discussion in 'Multiplayer' started by drmccollum, Aug 29, 2017.

  1. drmccollum

    drmccollum

    Joined:
    Mar 19, 2016
    Posts:
    10
    I'm looking for some help with the right way to move a client to a new scene server without unloading/loading scenes. I have multiple scene servers and on the client I async/additively load the scenes to give the appearance that it's a seamless terrain. I'm using a trigger on enter on a box collider over the area the new scene resides. The HLAPI API tries to load a new scene when the player connects to a new server. How can I disconnect from the active server and connect to a new server without unloading or loading scenes on the client using the LLAPI?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Also interested in this. My current solution of fading to black, switching scene/server, and fade back in is working but not what I would prefer.
     
  3. drmccollum

    drmccollum

    Joined:
    Mar 19, 2016
    Posts:
    10
    It appears that SceneManager.SetActiveScene is triggering the scenes to unload. Anyone know how to override that function to stop the unloading of the scenes?

    EDIT: After further testing, I don't think this has anything to do with SetActiveScene. Doesn't help that when I run in editor mode I get a CRC mismatch error, but it works fine in build mode.
     
    Last edited: Aug 31, 2017
  4. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    You must work with your own NetworkManager from scratch to obtain this behavior.

    Scene are not "Synchronized" like you seem to think. You can have a totally different scene on the client and the server.

    The only thing you need to really synchronized are networkIdentity in your scene. Changing scene is just telling the client which scene to load, nothing more.

    Unfortunately for the moment, i think it's not possible to keep networkIdentity alive when connecting from server to server. You have to work a lot to obtain this behaviour.
     
  5. drmccollum

    drmccollum

    Joined:
    Mar 19, 2016
    Posts:
    10
    The server connectivity is not the issue. I'm able to transfer the player from one scene server to another. The issue is that somewhere in the HLAPI flow, it forces the client to unload all other scenes.
     
  6. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    You have to write your own NetworkManager.

    The HALPI NetworkManager is bad and just do that when asking to a client a new scene :
    SceneManager.LoadScene(...)

    You CAN'T choose what you want to do when the scene message is received.

    The better if you don't want to write your own NetworkManager is to add your own SceneMessage Handler via LLAPI message system.

    Things I have done since today is to send the sceneName (bad for the moment), boolean for if the server want clients to load this scene immediately or not, bool for async or not (not sure it's necessary) etc...

    In my game I can choose to load "Loading scene", the game scene (send by server) at 0.9% before the server is ready and finish the load when the server become ready. After that I have in async all the UI for the party... :)
     
  7. Xype

    Xype

    Joined:
    Apr 10, 2017
    Posts:
    339
    The HLAPI pro which im 90% sure drmccollum is using has much better management, it handles switching scenes without the original bugs out the gate. However what he is experiencing is the HLAPI Pro does this by creating a seperate server instance for each scene, so when the character switches scenes it is having to basically change servers, even though you are only starting one headless server when you launch the server.

    This is an issue that has been talked about for a long time and I have never seen anyone come up with a good solution. Unity handles scenes in a pretty dumb way. The only theory I have had but havn't tested yet is to async load any "zones" the player is able to go to, when they first enter the zone that connects them. This would give you the seamless loading feel and then you would immediately start loading the connected zones again. This is a terrible way to do it, but it should work...ugly like. People have been barking at Unity to give us a way to keep scenes alive for a very long time. I mean all they have to do is allow us to apply don't destroy on load to scenes right sigh... However we are talking Unet here, which they have pretty much ignored for a long time now.
     
  8. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    He doesn't need to sync scene btw. If the purpose is just loading scene at specific place in space without random scene from server ... basically you just need to load the scene on client and to NetworkServer.Spawn();

    If you can keep your player from server to server ... your job is done. The server will have the same scene as client and client as server because at this location it's sure it's this scene which is loaded ! The sync is implicit by the player's location. What make the difference and need to be really sync ? Only networked object in this scene ... that's all.
     
  9. drmccollum

    drmccollum

    Joined:
    Mar 19, 2016
    Posts:
    10
    I'm not sure I follow you here, but the scene on the server should never change. It is static and will always be the same scene on each scene server. The client will load and unload the scenes as necessary. The final trick is to disconnect the client from one scene server to another that matches the active scene on the client.
     
  10. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    Yep, so you don't have to use the scene loading feature of netWorkManager.
    You "just" have to connect to the right server for the right scene.

    What is the problem exactly ? ^^
     
  11. drmccollum

    drmccollum

    Joined:
    Mar 19, 2016
    Posts:
    10
    I need someone from Unity to reply and tell me what triggers this:

    Unloading 6 Unused Serialized files (Serialized files now loaded: 0)
    UnloadTime: 4.767290 ms
    System memory in use before: 131.5 MB.
    System memory in use after: 130.7 MB.

    Unloading 147 unused Assets to reduce memory usage. Loaded Objects now: 6695.
    Total: 6.588418 ms (FindLiveObjects: 0.275900 ms CreateObjectMapping: 0.120140 ms MarkObjects: 5.147031 ms DeleteObjects: 1.043231 ms)

    Unloading 7 Unused Serialized files (Serialized files now loaded: 0)
    UnloadTime: 0.446150 ms
    System memory in use before: 130.9 MB.
    System memory in use after: 131.3 MB.

    Unloading 1 unused Assets to reduce memory usage. Loaded Objects now: 7330.
    Total: 3.637425 ms (FindLiveObjects: 0.339593 ms CreateObjectMapping: 0.126479 ms MarkObjects: 3.161390 ms DeleteObjects: 0.008753 ms)
     
  12. drmccollum

    drmccollum

    Joined:
    Mar 19, 2016
    Posts:
    10
    I have this almost working and have run into what I hope is the last technical issue. I need to be able to assign a network identity to the existing player gameobject after the client connects to the new server. I tried using ReplacePlayerForConnection, but it doesn't work because the existing player GO doesn't have a network identity.

    Any ideas on how to assign a network id to the player gameobject?