Hi guys,
This issue is killing me. I`ll explain the full cenario:
Im using MatchMaker to create, list and join matches. Nothings wrong with that, and I also have my custom NetworkManager with autoCreatePlayer checked, my playerPrefab, online and offline scenes set.
My online scene have scripts that needs player`s references. But the player not already exists in online scene, so what I did was:
In my custom NetworkManager I overrided OnServerAddPlayer method, and there I resolved all dependencies that needed the player instance, before calling NetworkServer.AddPlayerForConnection, and that worked, but ONLY for host player.
When another player connects as a client, the method OnClientConnect is called, but when I call ClientScene.AddPlayer(conn, 0) from there, no OnServerAddPlayer method is called for the client. It seens like AddPlayer Message is not being sent, and I don`t know why.
Online documentation tells that every ClientScene.AddPlayer will call OnServerAddPlayer. I already tried not to overried OnClientConnect method, but nothings changeded.
What can be wrong? There is my custom NetworkManager code:
public override void OnClientConnect(NetworkConnection conn)
{
Debug.Log("Entered OnClientConnect");
ClientScene.AddPlayer(conn, 0);
}
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
{
Debug.Log("Entered OnServerAddPlayer");
var player = (GameObject)GameObject.Instantiate(playerPrefab, GetStartPosition().position, Quaternion.identity);
if(NetworkManager.singleton.numPlayers > 0){
player.tag = "Default";
}else{
player.tag = "Player";
}
if(NetworkServer.AddPlayerForConnection(conn, player, playerControllerId)){
player.GetComponent<PlayerNetworkSetup>().SetUpPlayerDependencies(player.GetComponent<Player>());
}
}
Thanks for helping, and sorry for my bad English.