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. Dismiss Notice

How to create a Loading Bar compatible with NetworkManager Scene Transitions?

Discussion in 'Multiplayer' started by moco2k, Apr 5, 2016.

  1. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    Hey,

    I have some problems figuring out how to implement a loading bar for scene transitions which are initiated by the NetworkManager. Basically, I have a custom NetworkManager which inherits from the original class and just overrides some virtual functions, so really nothing special.

    First, I thought about using a custom script that replaces the SceneManager.LoadSceneAsync() calls in the NetworkManager. Unfortunately, however, for the client, the NetworkManager has the scene transition in ClientChangeScene() and this function cannot be overriden. Only ServerChangeScene() can be overriden.

    Then, I thought about retrieving s_LoadingSceneAsync from the NetworkManager. This variable stores the AsnycOperation which is generated when the scene transition starts. With this reference, I guess an approach like this would be possible. Unfortunately, this variable is not public.

    Am I missing something obvious?
    I do not want to copy+paste the complete NetworkManager source and create a completely custom one just for this single modification.

    I have the feeling that either the API of the NetworkManager or of the SceneManager is missing something, maybe even both. Unfortunately, there is neither something available like SceneManager.OnStartLoadingScene() nor SceneManager.GetCurrentAsyncOperation() which would easily solve the issue. And the NetworkManager does not seem to provide any options to hook into the scene loading either.

    Does anyone else have figured out a nice solution for this?

    Any help is much appreciated.
     
    Last edited: Jul 26, 2016
    Deleted User likes this.
  2. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    752
    How I did this for the time being is additive loaded my loading scene, and just manually updating the progress bar based on time. I know when it is finished loading by overriding some of the methods in NetworkManager, and by sending a message from the server to the client when it finishes the OnServerReady logic.
     
  3. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    At which point in the code did you start your loading script for the client?
    Is this a point at which you already know that the connection is successful and you are definitely going to load a new scene? This would be the point I would prefer to hook up to, but I cannot find a proper hook.

    Otherwise, if the loading is started at an earlier point, the loading would need to be cancelled in case that the connection fails. This would require additional code and feels like a less clean solution for me.
     
    Last edited: Apr 6, 2016
  4. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    752
    I start the loading scene as soon as I start the client, and if OnClientConnect is not called within a few seconds I take them back to the connect screen. OnClientConnect is called after the client successfully connects to the server. I have not been able to get the error reporting to work, so I never get events for the connect failed, thus why I take them back after a couple seconds.
     
  5. Deleted User

    Deleted User

    Guest

    @moco2k Did you ever figure out a clean way to hook this up? I'm working on scene transitions, and things are handled in different places depending on if going from offline to online, online to online, or online to offline. Thanks for any help.
     
  6. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    Nope. :/ Unfortunately, I haven't found a clean solution to this yet with some nice hook to the SceneManager or NetworkManager.