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:
public void Rpc_SyncBoardData(Vector3 _team1BaseLocations, Vector3 _team2BaseLocations, int _boardHeight, int _boardWidth)
team1BaseLocations = _team1BaseLocations;
team2BaseLocations = _team2BaseLocations;
boardHeight = _boardHeight;
boardWidth = _boardWidth;
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
5 days ago
How did you do that? LIke wait until start method invoked
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
100 People are following this question.
[FIXED] Networking timeout when sending from Server to Client
Can't recreate a match using UNET matchmaker
Client choice of prefabs on a NetworkLobbyManager
UNET - Prevent Local Client to receive Server Command!
Photon ccu question