- Home /
Odd behaviour when sending rpc from client to server
I'm creating a turn-based board game with different phases. I have succeeded in synchronizing movements and turns without much hassle.
This code lets the server know when all the players have finished their moves. This one works just fine.
public void setDoneMoving() {
if (Network.isServer)
rpcSetDoneMoving(Network.player);
else
networkView.RPC("rpcSetDoneMoving", RPCMode.Server, Network.player);
}
[RPC]
private void rpcSetDoneMoving(NetworkPlayer player) {
if (this.members.ContainsKey(player.guid)) {
this.members[player.guid].setReady(true);
}
bool nextPhase = true;
foreach (LobbyGuestScript.Member m in this.members.Values)
if (m.getReady() == false)
nextPhase = false;
if (nextPhase)
this.setNextPhase(Phase.Board);
}
This code notifies the server when the board has finished performing actions.
public void addMovingConveyor() {
if (Network.isServer)
rpcAddMovingConveyor(Network.player);
else
networkView.RPC("rpcAddMovingConveyor", RPCMode.Server, Network.player);
}
public void setConveyorDoneMoving() {
if (Network.isServer)
rpcSetConveyorDoneMoving(Network.player);
else
networkView.RPC("rpcSetConveyorDoneMoving", RPCMode.Server, Network.player);
}
[RPC]
private void rpcAddMovingConveyor(NetworkPlayer player) {
Debug.Log("rpcAddMovingConveyor was called");
this.activeConveyorCount++;
}
[RPC]
private void rpcSetConveyorDoneMoving(NetworkPlayer player) {
Debug.Log("rpcAddMovingConveyor was called");
this.activeConveyorCount--;
if (this.activeConveyorCount == 0)
if (this.phase == Phase.Express)
this.setNextPhase(Phase.Board);
else
this.setNextPhase(Phase.Lasers);
}
Despite being so similar this code does not get called. I've tried having browser, stand-alone and Unity editor for both client and server. The rpc function will only get called when BOTH instances run as Unity editor mode.
Answer by Seerix · May 27, 2014 at 04:17 PM
I managed to fix this issue myself. I decided to leave it alone for a while and focus on different functions first. I then found a related bug in other code which caused the rpc function to fail.
The weird thing about this is that the failing code should not prevent my Debug.Log from being called. This made it look like the function was not being called, except when running both client and server in the Unity editor.