hosting a master server on a different scene

Hey, I am making a multiplayer strategy game and because I am using the same scripts on every character, I am using networkView to define when the player is controlled by me, so the scripts on this player are enabled. anyway. the problem is that when i host the server from a different scene I can’t define when the nerworkView is mine! is there any way that i can host a server from a different scene and get the networkView boolean to true when the player is controlled by me?

The answer depends a bit on how you are using your scenes, but in my case I wanted to be able to have somebody on the main menu scene join a game that could be ongoing in any other scene, and not create any characters until after the joiner loads the other scene.

To do this I have the server use Network.Instantiate() (and this is the only time I use it) to create a ‘network management’ object that persists between scenes. I use this object to do general handshaking. The clients wait for the object to be created then start off the handshake by sending an RPC asking which scene to load, and the server responds with an RPC telling it which scene. Once the client loads the scene, it then sends another RPC telling the server it is ready to receive the list of characters. The server sends an RPC for each character that indicates which prefab to use for instantiation, where to instantiate it, and what the NetworkViewID should be. The last bit is important for the character to be synchronized.

Finally, the client creates a NetworkViewID of its own and sends it to the server in an RPC asking the server to re-assign a character to that NetworkViewID, so that the client owns it. If there are multiple clients then the server will need to forward NetworkViewID to them so that they also assign the new NetworkViewID to that character.

[RPC]
void SetObjectAssignment(NetworkViewID oldId, NetworkViewID newId)
{
	NetworkView networkView = NetworkView.Find(oldId);
	networkView.viewID = newId;
}

Keep in mind that whoever owns the object needs to be the one who created the NetworkViewID.

This is not a straight-forward process, but I think any game more complicated than a tech demo will need to follow something like this.