Search Unity

ClientRpc not triggered after Reconnecting

Discussion in 'Multiplayer' started by WongKit, Apr 27, 2017.

  1. WongKit

    WongKit

    Joined:
    Apr 27, 2017
    Posts:
    26
    Hi,

    I am quite new to Unity and already struggling with the network communication. I plan to set some player properties, when a new client connects. In this stripped down example, I simply set the rotation of the current client GameObject.

    According to the documentation, ClientRpc Commands are executed on all clients objects - also in the server instance. When I host the game using the NetworkManager HUD, the scripted player rotation is correctly set as expected.
    However, when I stop and reconnect the host session, my ClientRpc call is not triggered anymore. The rotation command is not executed. See the 30 seconds video attached.


    PlayerController.cs

    Code (CSharp):
    1.     ...
    2.     using UnityEngine.Networking;
    3.  
    4.     public class PlayerController : NetworkBehaviour {
    5.         void Start () {
    6.             GameManager.instance.registerPlayer (gameObject);
    7.         }
    8.     }
    GameManager.cs

    Code (CSharp):
    1.     ...
    2.     using UnityEngine.Networking;
    3.    
    4.     public class GameManager : NetworkBehaviour {
    5.    
    6.         public static GameManager instance;
    7.    
    8.         void Awake() {
    9.             instance = this;
    10.         }
    11.        
    12.         public void registerPlayer(GameObject player) {
    13.             Debug.Log ("registerPlayer");
    14.             RpcPosition (player);
    15.         }
    16.    
    17.         [ClientRpc]
    18.         public void RpcPosition(GameObject player) {
    19.             player.transform.Rotate(new Vector3 (45, 45, 45));
    20.         }
    21.     }
    22.  
    I do not know if this behaviour is intended or if I did/understood something wrong.
    Of course, setting a rotation could be done in a different manner, but I am using ClientRpc calls for a different purpose in my project when new clients join a game.

    I also posted this question in the Unity answers area 3 days ago. As there was no response (and the question slowly disappears in the further pages), I am trying my luck here.

    Regards
    WongKit
     

    Attached Files: