Hello! Im new with networking and im making my first multiplayer game. Everything has been almost too easy to implement but i’ve been hitting my head to a wall for few days with this issue.
I want to make a chat window (similar with league of legends) where player selects his character before the game starts. Im having problems with spawning all player characters, the game works fine if the server is initialized and connected in the same scene so i can call spawnPlayer function inside OnConnectedToServer and OnServerIntitialized. I need however load a new scene after the chat window is over.
If i try to call spawnPlayer inside function Start or OnLevelWasLoaded the new players cant see the players that are already in the game.
in menu scene:
if (GUILayout.Button("New Server")){
Network.InitializeServer(32,parseInt(ServerPort),false);
}
if (GUILayout.Button("Connect")){
Network.Connect(Mynetwork.ServerIP,parseInt(Mynetwork.ServerPort));
}
function OnServerInitialized(){
Application.LoadLevel("Testbed");
}
function OnConnectedToServer(){
Application.LoadLevel("Testbed");
}
In game scene:
function OnLevelWasLoaded()
{
spawnPlayer();
}
function spawnPlayer()
{
var PlayerTransform : Transform = Network.Instantiate(player, Vector3(0,10,0) ,transform.rotation, 0);
var playerName : String = Mynetwork.PlayerName;
PlayerTransform.networkView.RPC("setPlayerProperties", RPCMode.AllBuffered, playerName);
}
If a new player connects he is getting error “Received state update for view id’ AllocatedID: 1’ but the NetworkView doesn’t exist” the host however works just fine. So my question is, where i should actually call this spawnplayer function?