Why is this ClientRPC not executed?
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.
Answer by mastegar · May 04, 2016 at 03:36 PM
I found out why it didn't work. I was calling the ClientRpc method before the game player objects on clients were properly set up by OnLobbyServerSceneLoadedForPlayer. To fix it I just waited with calling the ClientRpc until after the start method was invoked on all client gameplayer objects.
Answer by ferrisbuellers · Apr 19, 2017 at 10:55 AM
How did you do that? LIke wait until start method invoked
Your answer
Follow this Question
Related Questions
How do I get the true position (Vector 3) from a Network Transform Component(Unet)? 0 Answers
Day/Night cycle turns black at night and how to Serialize it rightly? 0 Answers
Photon Networking - How to move all players from game scene to current room scene? 0 Answers
How to count score on all players from non player object 0 Answers
unity NetworkingLobbyManager problem 0 Answers