Unet Online Scene Selector, Choose from multiple maps, etc.
All I want is a way to choose what online level will be loaded. Maybe make it something players in a lobby can vote for, eventually.
I've spent enough time searching to assume that NetworkManager.ServerChangeScene is the answer, but I don't know how it's implemented. The advice I found is written for other knowledgeable programmers, which I am not. Nor are those asking, usually. Still, couldn't hurt to try for myself.
If you could even just direct me to an example where this has been made to work, or tell me what to type where, I can figure out the rest. Please help. Thank you.
Answer by sovium · Mar 15, 2016 at 09:25 PM
Hello @jinnindo,
When you set your online/offline scene in NetworkManager, a method NetworkManager.ServerChangeScene is called automatically in the background. When this method is called, the NetworkManager.OnServerSceneChanged is called on the server and NetworkManager.OnClientSceneChanged is called on the clients. These methods can be overridden and customized. If you are using the networkmanager, you can get the instance of your networkmanager by writing NetworkManager.singleton.
So at the point where you would like to globally change your scene (server & clients), you should have something like:
void ChangeScene(string sceneName){
// Change scene on the server
NetworkManager.singleton.ServerChangeScene(sceneName);
}
In addition, according to the documentation you need to set clients to be ready again after changing the scene, so for example you could override the NetworkManager's method:
public override void OnClientSceneChanged(NetworkConnection conn){
base.OnClientSceneChanged(conn);
// Set client as ready
ClientScene.Ready(conn);
}
See following links for more information:
NetworkManager.ServerChangeScene
I appreciate your response, but I think this highlights the problem.
At best, I have an artist background. I did find the links you shared here, but couldn't make sense of them (hence asking where to put the code). Until! I found that the network starter example here: http://forum.unity3d.com/threads/networking-sample-projects.325096/, which has an implementation of changing online scenes. It is the only example I've found or even heard of.
I still don't know how exactly to choose the online scene, except manually using that button, and only after a scene has already loaded. Players voting on maps is even farther away.
I came back around to searching for the solution to this problem and found this old question/answer. Since it's been 2 years and I've sort of learned to program in that time, I can now say yours is the correct answer. Thank you, friend!
Answer by NarxGaming · Sep 06, 2020 at 08:18 AM
A TOTALLY DIFFERENT MAYBE BETTER WAY! if anyone cares hahah =)
you can create Multiple Lobbys as Scenes with seperate instances of Lobby manager with play scene set to some different scene .. then when you Host add a prefix onto match.name ie..
manager.matchName = "F_" + roomNameField.text ; // An InputField.text
Then when you check for rooms available, you can then only display rooms available to join that have the prefix at beginning ie.
foreach (var match in manager.matches)
{
string checkMatchName = match.name;
if (checkMatchName.StartsWith("F"))
{
if (GUI.Button(new Rect(xpos, ypos, 200, 40), "Join " + match.name))
{
manager.matchName = match.name;
manager.matchSize = (uint)match.currentSize;
manager.matchMaker.JoinMatch(match.networkId, "", "", "", 0, 0, manager.OnMatchJoined);
}
ypos += spacing;
}
}
Thus only Displaying Rooms with the PreFix "F" available to join, so use different PreFixes for different lobbies and Clients can then only connect to Matches in the required lobby =)
Your answer
Follow this Question
Related Questions
UNET StopServer() without reloading lobby scene 2 Answers
How to make Server Side Bots in Mirror? 0 Answers
Is ther any way to load text after building game 0 Answers
HELP with Unity Networking 0 Answers
How to correctly change scene with a Lobby Manager? 0 Answers