ClientRPC not called from command on client instance during Start()
Good morning all,
I am implementing a Server/Client based multiplayer game using Commands and ClientRPC's.
1) I currently have a GameController (server only) object that contains information about the game.
2) Upon a new client joining the game, I am attempting to initialise the player with information contained in the GameController (i.e. TeamId, SpawnLocation).
3) In the Start() method, I call CmdInitialisePlayer(), which requests data from the GameController and calls ClientRPC's to save that data on the local client Player object.
public class Player : NetworkBehaviour
{
private int id;
private int myTeamId;
public const string PLAYER_TAG = "Player";
void Start()
{
id = FindObjectsOfType<Player>().Length - 1;
RegisterModel(PLAYER_TAG, id);
spawnController = GameObject.FindGameObjectWithTag(SpawnController.SPAWN_CONTROLLER_TAG).GetComponent<SpawnController>();
if (isLocalPlayer)
{
// Player Initialisation
CmdInitialisePlayer();
// Canvas Settings
Canvas canvas = GetComponentInChildren<Canvas>();
canvas.planeDistance = 1;
canvasController = canvas.GetComponent<CanvasController>();
}
if (!isLocalPlayer)
{
DisableNonLocalCompontents();
AssignLayer(REMOTE_LAYER_NAME);
}
}
[Command]
void CmdInitialisePlayer()
{
GameController gameController = GameObject.FindGameObjectWithTag(GameController.GAME_CONTROLLER_TAG).GetComponent<GameController>();
Transform transform = gameController.GetPlayerTransform(id);
RpcSetPlayerTransform(transform.position, transform.rotation);
RpcSetMyTeamId(gameController.GetMyTeamControllerId(id));
}
[ClientRpc]
void RpcSetPlayerTransform(Vector3 position, Quaternion rotation)
{
Debug.Log("rpc transform");
transform.rotation = rotation;
transform.position = position;
}
[ClientRpc]
void RpcSetMyTeamId(int teamId)
{
Debug.Log("rpc myTeamId");
myTeamId = teamId;
}
}
I believe this is the correct way to have my code structured and when I run it within a host/client setup everything works as expected. However, when a client only instance joins, the ClientRPC's appear to not be executed as my Debug.Log() calls are not displayed within the logs, furthermore, the Player.myTeamId or Player.transform parameters are not set.
Any help with this would be greatly appreciated.
Your answer
Follow this Question
Related Questions
Photon RPC 2 Answers
How to change turns on button click using HLAPI? 0 Answers
UNET Commands calling advice. Calling Commands from CHILD object 1 Answer
How to command dedicated server 1 Answer
[Command] Not being called at all 0 Answers