RPC not firing from Server to Client

Hello!

I’ve been wrestling with this issue for quite some time now. Firstly here’s the script:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Room : MonoBehaviour {
	
	private bool __enable_start = false;
	
	void OnLevelWasLoaded() {
		if (Network.isClient) this.networkView.RPC("RegisterPlayer", RPCMode.Server, ToolBox.SerializeBase64(Player.instance.player_data));
	}
	
	void OnGUI() {
		Game game = Player.instance.game;
		if (game != null) {
			GUILayout.BeginArea(new Rect(10, 10, Screen.width - 20, Screen.height - 20));
			GUILayout.BeginHorizontal();
			GUILayout.BeginVertical(GUILayout.Width(300), GUILayout.ExpandWidth(false));
			
			this.__enable_start = true;
			
			//teams
			int team_count = game.teams.Count;
			GUILayout.Label("Teams");
			GUILayout.Space(10);
			
			for (int i = 0; i < team_count; i++) {
				GUI.enabled = true;
				GUILayout.Space(10);
				GUILayout.Label(game.teams*.team_name);*

_ if (game.teams*.players.Count > 0) {_
_ for (int j = 0; j < game.teams.players.Count; j++) {
GUILayout.BeginHorizontal();
GUILayout.Box(game.teams.players[j].name());_

if (game.teams.players[j].id() == Player.instance.player_data.id()) {
_ if (GUILayout.Button(“Leave team”, GUILayout.Width(100))) {_
game.LeaveTeam(Player.instance.player_data);
_ }
}
GUILayout.EndHorizontal();
}
} _

else this.__enable_start = false;*

int open_slots = (game.max_players / team_count) - game.teams*.players.Count;
GUI.enabled = !game.HasTeam(Player.instance.player_data);
if (open_slots > 0) {
for (int k = 0; k < open_slots; k++) {
_ if (GUILayout.Button(“Open slot”)) {_
game.JoinTeam(game.teams, Player.instance.player_data);
_ }
}
}
}*_

* GUILayout.EndVertical();*
* GUILayout.Space(20);*
* GUILayout.BeginVertical(GUILayout.Width(100), GUILayout.ExpandWidth(false));*

* //players*
* GUI.enabled = true;*
* GUILayout.Label(“Players”);*
* GUILayout.Space(10);*
* foreach (PlayerData player in game.players) {*
* GUILayout.Space(10);*
* GUILayout.Box(player.name());*
* }*

* GUILayout.EndVertical();*
* GUILayout.Space(20);*
* GUILayout.BeginVertical(GUILayout.Width(100), GUILayout.ExpandWidth(false));*

* //game options*
* GUI.enabled = Network.isServer;*
* GUILayout.Label(“Game options”);*

* GUILayout.Space(20);*
* game.type = (Game.Type) GUILayout.SelectionGrid((int) game.type, new string[]{“Deatchmatch”, “CTF”}, 1);*

* GUILayout.Space(20);*
* if (!(game.players.Count > 0)) this.__enable_start = false;
GUI.enabled = this.__enable_start && Network.isServer;
_ if (GUILayout.Button(“Start game!”)) {
Debug.Log(“Starting game”);
}*_

* GUI.enabled = true;*
* if (GUILayout.Button(“Disconnect”)) {*
* Player.instance.network_connector.Disconnect(200);
_ }*_

* if (GUILayout.Button(“Force”)) {*
* this.networkView.RPC(“RegisterGame”, RPCMode.Others, ToolBox.SerializeBase64(Player.instance.game));*
* }*

* GUILayout.EndVertical();*
* GUILayout.EndHorizontal();*
* GUILayout.EndArea();*
* }*
* } *

* void OnApplicationQuit() {*
if (Network.isServer) ToolRequest.WWWRequestXML(this, “cancelgame”, “http://hidden_for_security?action=cancel&id=” + Player.instance.game.id);
* }*

* void OnDisconnectedFromServer() {*
if (Network.isServer) ToolRequest.WWWRequestXML(this, “cancelgame”, “http://hidden_for_security?action=cancel&id=” + Player.instance.game.id);
* Player.instance.game = null;*
* SceneManager.instance.LoadLevel(“lobby”);*
* }*

* void OnWWWResponseReceived(Response response) {*
* if (response.identifier == “cancelgame”) SceneManager.instance.LoadLevel(“lobby”);*
* }*

* [RPC]*
* void RegisterPlayer(string serialized_player) {
PlayerData player = (PlayerData) ToolBox.DeserializeBase64(serialized_player);
_ Player.instance.game.JoinGame(player);
this.networkView.RPC(“RegisterGame”, RPCMode.Others, ToolBox.SerializeBase64(Player.instance.game));
}*_

* [RPC]*
* void RegisterGame(string serialized_game) {
Game game = (Game) ToolBox.DeserializeBase64(serialized_game);
_ Player.instance.game = game;
}*_

}
So the issue here can be described as the following: I have a host starting a server which has a variable name accessible through Player.instance.game (Player is an extended MonoBehaviour with a NetworkView component). Now when another player connects its sends its data to the player’s game instance with a RPC [Player.instance.game.JoinGame(player);]. This works for the host(!), in response to this the host sends the player a copy of his game object, also with a RPC, but somehow, this RPC does not get triggered. Also when I force the RPC mid game (so when both levels are the same and loaded, and both the client and host have the same scripts active and running) it doesn’t work either.
Does anybody have any idea what is going wrong?
Thnx!

Ok I think I found it. Unfortunately this was all my bad, due to my testing process I built and ran another instance of the game (where I did not see the debugging of course). When I turned this process around, and hosted a game in the editor it actually showed an error before even sending the RPC! Apparently there was one object type which could not be serialized (the Color class of UnityEngine). I then tried unserializing it all together, but that did not work. The game class had to be serialized for some reason, which is ok, because after removing the color thing it worked perfectly. Then I tried implementing the allocated ID process. Which worked partly, what I did was upon a player entering the Room level is creating an alloctedID on the server, then sending this to ALL with RPC, the actual setting of the ViewID happened in the RPC (so I assumed that everybody would get the same viewId at the same time). This did not work however completely. Because after setting the AllocetedID I immediately called a RPC but it spat out an error saying it could find the AllocatedID. Which was weird because a text field in the game actually showed that they were the same. Assuming this was a sync error, I forcefully fired the same RPC again, this time with success! To avoid complications for now and later (what if a third man enters, that is not synced up with the other two? how will he get this viewID), i put everything back to my original settings. If you have any suggestions on good readings for ViewIds, I would be much obliged. Thank you for your help!