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 NetworkManager.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, NetworkManager.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. Maybe you can check s_LoadingSceneAsync.progress (and possibly set s_LoadingSceneAsync.allowSceneActivation = false if you need to) via reflection.
s_LoadingSceneAsync.allowSceneActivation = false
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/Manual/UNetSceneObjects.html In short, when scene loaded, call on sever NetworkServer.SpawnObjects() to activate scene objects with network identity.
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.
Thank you for your answer. I'll try it :)
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 SceneManager.sceneLoaded event instead 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 NetworkManager as final solution - it was created for simple games/prototyping. Take a look at Unet components' source code, especially at NetworkManager to undrestand more, there is no magic: https://bitbucket.org/Unity-Technologies/networking
I looked at unet sources and NetworkManager 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 NetworkManager 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).
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
10 People are following this question.
Unity TCP async functions
How to load levels with animation GUI
Got a problem with Async!
Display loading/progress indicator from Start()?
UNet: How to get isLocalPlayer from a parent