- Home /
Network Level Loading: Best practice for getting hosts' current level name?
Sorry if this is too long - tl;dr version at the bottom of all this!
I'm working on a shooter that has two types of server modes - a dedicated "headless" mode and a "play and host" mode which is like today's shooters, where you are able to play while various server player scripts handle the I/O load.
At the moment, I have a script, used in the gameMenu scene that handles the main menu. I also have a class that is called "NetworkLevelLoader" to help ease the pain of network level loading (it will automatically go through the process to stop the message queue, etc etc, while the level loads).
The main menu checks all the input, etc and then starts a connection to the server once a button is clicked. At the moment, the server and client both talk to each other correctly when I manually load the level explicitly (apart from some Scene NetView ID mismatches and warnings, but since I anticipate more than 1 map in the game, I need a method that reports back to the new client what level is currently being played, which the client will then load and sync up.
The current implementation is this:
// server side logic script on a gameObject with a networkView.
// This script only fires if it's the server (aka connected clients don't have a say
// on what level to load)
[RPC]
void clientLoadLevel(string levelName) {
NetworkLevelLoader.Instance.Load(levelName);
}
void OnPlayerConnected(NetworkPlayer player) {
networkView.RPC("clientLoadLevel", player, Application.loadedLevelName);
}
That code is not 1:1 to the actual code in the project as the dev machine is at the office, but I guess you can get the idea. In fact, that code might even work. I dunno.
The main menu scene has a gameobject that has a script which contains the same "clientLoadLevel" function in it so that it can trigger the level load. However, when I get the server to relay the level name to the client, it throws a error (I forget the exact error message, but something like NetworkView inconsistent), or the call just falls on deaf ears, leaving the client stuck in limbo.
tl;dr version: Could someone please shine some light on how to tell clients on connecting to a server that's already in-game what level to load?
Thanks for the help, I appreciate it. It must be something I'm overlooking.
Okay, after some more tinkering, I can confirm that I am getting the RPC. However, what does this mean?
View ID SceneID: 2 Level Prefix: 0 not found during lookup. Strange behaviour may occur
Could't invoke RPC function 'clientLoadLevel' because the networkView 'SceneID: 2 Level Prefix: 0' doesn't exist
The client is then stuck at the "Starting the game" screen that pops up.
The main menu is actually scene 2 in the level build dialog... but why am I getting this? Scene 2 has a gameobject that handles the menu and THAT has a NetworkView attached.
Your answer
Follow this Question
Related Questions
Network servers are overlapping in the multiplayer menu 0 Answers
How can I send RPC from one client to another client directly in multiplayer game? 0 Answers
Unet Networking: having two clients in the editor instead of building for standalone? 0 Answers
Client shooting is lagging 0 Answers
Send and recieve variables to all clients using smartfox 0 Answers