- Home /
Loading Progress using UNET
How to display loading progress while i'm using UNET. Here i have offline scene and online scene or maybe i switching scene and how to show loading progress?!
I've looked. This is in the networkmanager class, but its not possible to get to it Network$$anonymous$$anager.s_LoadingSceneAsync = Application.LoadLevelAsync (newSceneName);
Hope other people have found a way to get to it :(
@bittarello did you solved this problem that you faced ? Is that worked?
As @AlanGreyjoy said, Network$$anonymous$$anager.cs is already using LoadSceneAsync
in ServerChangeScene
and ClientChangeScene
and is storing the loading operation in s_LoadingSceneAsync
. It it used for the initial online scene (`StartServer`) and the final offline scene loading (`StopServer`), and also for online scene switching.
s_LoadingSceneAsync
is static private but in theory accessible via reflection. $$anonymous$$aybe you can check s_LoadingSceneAsync.progress
(and possibly set s_LoadingSceneAsync.allowSceneActivation = false
if you need to) via reflection.
Oddly enough, s_LoadingSceneAsync.allowSceneActivation is set to true after checking s_LoadingSceneAsync.isDone, which should be redundant.
Answer by snaildex · Mar 19, 2016 at 10:05 AM
Make your custom NetworkManager by deriving standart, then in OnStartServer and OnClientConnect events use SceneManager.LoadSceneAsync function to load scene, and then in event OnLevelWasLoaded check who is calling this event (server or client) and do smth - spawn etc. That worked to me to load battlefield in my game. And to display progress on clients just use asyncoperation returned by LoadSceneAsync like in offline games. Using only standart NetworkManager won't give you that result.
I'm trying this approach but when the host (I didn't try with other client) gets in the new scene, the network identity objects ,that were already spawned in the scene, stay disabled. Before I try this async load, with server level change it was working. I thought that client ready message was missing, but wasn't that. Do you have any solution?
Read this: https://docs.unity3d.com/$$anonymous$$anual/UNetSceneObjects.html In short, when scene loaded, call on sever NetworkServer.SpawnObjects() to activate scene objects with network identity.
@bittarello did you solved this problem that you faced ? Is that worked?
yes, you have to tell to each client to change its scenes using async and sending the progress to the host. When all clients and host gets 0.9 of progress, the host tell everybody to change the scene locally. This loaded scene can't spawn the object when the host loads it. It needs to receive a message (you have to create one or using RPC) from clients telling they are in that scene. With all confirmation, you can call NetworkServer.SpawnObjects(). I hope it is it. Good luck.
OnLevelWasLoaded() has been deprecated and will be removed in a later version of Unity. I guess it's not the best way to solve the issue. Futhermore, if i have more than 1 online scene, i should know which one to load in OnClientConnect(), how do i know that? I think i should receive scene message on clients before.
Now you can use Scene$$anonymous$$anager.sceneLoaded event ins$$anonymous$$d of OnLevelWasloaded. I did not find any possibility to pass automatically additional data to client when connected, so yes, you need to do it manually by custom messages. And, since you have several scenes on server, ensure all your networkIdentities have correct sceneID (can be set manually by ForceSceneId method after scene loading) so they will appear only in specified scenes on clients. And don't think about Network$$anonymous$$anager as final solution - it was created for simple games/prototyping. Take a look at Unet components' source code, especially at Network$$anonymous$$anager to undrestand more, there is no magic: https://bitbucket.org/Unity-Technologies/networking
I looked at unet sources and Network$$anonymous$$anager hoping that i could not derive anything from it and just rewrite it a bit, since overriding ClientChangeScene is impossible in derived classes, but, unfortunately there are some use of internal uNet functions, those can not be accessed that way. So i guess i have only two options: derive from Network$$anonymous$$anager and try to do smth dealing with all the limitations, or switch to using networktransport, which very likely will require to rewrite my network code (there is a lot).
Your answer
Follow this Question
Related Questions
Problem with Application.Quit and Async networking 0 Answers
Async level load in 3.5 0 Answers
Loading Bar for Awake Function 1 Answer
Unity.Networking (UNet) RPC to Specific Player? Master Server? 4 Answers
TCP/IP Stream.Read doesnt work 0 Answers