Hello, I have a problem here, I have a script like this in the player: Code (CSharp): void Start(){ if (isLocalPlayer){ Cmd_call_print(); } } [Command] void Cmd_call_print(){ Rpc_print(); } [ClientRpc] void Rpc_print(){ print("Hello"); } When a player spawn and do his Start() he prints "hello" in all clients (including host). I have no problem with this script when I use the NetworkManager, but if I use it with the NetworkLobbyManager the host can't send the ClientRpc, and if I try to call it whenever I want, the host can't send the Rpc but the clients calling the Cmd_call_print can call the Rpc_print(). I have no clue what happens here so I need help please.
Same issue here - even while using the provided Lobby Example from the asset store, clients calling Cmd will trigger an Rpc but if a client (who also happens to be the host) calls a Cmd, nothing happens. Found a workaround - but it scales horribly (having a lot of Cmd / Rpc pairs will result in unreadable code). Here it is: Code (CSharp): void Start() { if (isLocalPlayer) CmdPrint(); } [Command] void CmdPrint() { // For the other clients RpcPrint(); // For the server itself Print(); } [ClientRpc] void RpcPrint() { Print(); } void Print() { Debug.Log("Hi"); }
[UPDATE] Changing the attribute [ClientRpc] to the deprecated [RPC], inverses the problem: Servers get the Rpc, but Clients do not. Unfortunately the results are the same if you stack the attributes.
[DIRTY_FIX] This seems after all to be related to the Player's Network Identity's Observers - the host object doesn't have itself in that list - therefore it is not receiving Rpc's. The fix is quite simple: Code (CSharp): foreach (NetworkIdentity nI in FindObjectsOfType<NetworkIdentity>()) nI.RebuildObservers(true); The problem is placing this code - ideally it should be placed whenever a new player is connected. Good luck
Thanks a lot man!! but unfortunately I have made my own lobby with the network manager, is a bit complex but it worked so.. XD