I am trying to sync some variables (Vector3 arrays and integers) over the network via a ClientRpc method in a NetworkBehaviour script. This script is attached to gameplayer prefabs which are created by unity on entering the play scene (I use a NetworkLobbyManager).
But the ClientRpc method isn’t executed. I have checked multiple times if I did everything right syntax wise and I looked through the manual and scripting API in search of clues, but I haven’t been able to come up with an explanation of why the method won’t fire. It looks like this:
[ClientRpc]
public void Rpc_SyncBoardData(Vector3[] _team1BaseLocations, Vector3[] _team2BaseLocations, int _boardHeight, int _boardWidth)
{
team1BaseLocations = _team1BaseLocations;
team2BaseLocations = _team2BaseLocations;
boardHeight = _boardHeight;
boardWidth = _boardWidth;
StartCoroutine("WaitForGameManager");
}
This ClientRpc is called on the server only, from a MonoBehaviour class on another gameobject. That line looks like this:
localPlayer.Rpc_SyncBoardData(team1BaseLocationsArray, team2BaseLocationsArray, (int)boardHeight, boardWidth);
I have already tried a lot of things to see what’s wrong with it. I tried invoking the function without arguments and from the game player prefab itself, instead of another gameobject. I tried another ClientRpc method which also didn’t work. I double checked if I have a NetworkIdentity attached (I have and it is set to Local Player Authority) and if the script inherits NetworkBehaviour. Nothing fixed it.
What could be the problem here? Am I not seeing something obvious?
There is also a NetworkTransform attached to the game player prefab. Perhaps that affects the ClientRpc calls. Furthermore, no errors are raised so I have absolutely no clue.