- Home /
The question is answered, right answer was accepted
Client can't modify a gameobject from server
Hello !
I have a network problem : my multiplayer game contains a scene where every player converge just before starting the real game. There is a chat in it and some texts meshes which (should) display the name of the players connected.
At first, a player creates a server and comes first in this scene. Then an other player connects to it and comes to this same scene. The chat is actually working, so they are clearly well connected...
In this waiting room scene, there is a game object with only this script attached :
var playersList:PlayersList;
class PlayerData {
var nickname:String;
var kills:int = 0;
var deaths:int = 0;
}
class PlayersList {
var players:PlayerData[] = new PlayerData[8];
var maxNbPlayers = 0;
var currentIndex = 0;
}
function Start() {
if (!Network.isServer)
{
networkView.RPC("SendNickname", RPCMode.Server);
}
else
{
playersList.maxNbPlayers = Network.maxConnections;
networkView.RPC("SendNickname", RPCMode.All);
}
}
@RPC
function SendNickname() {
var name:String = PlayerPrefs.GetString("Player Name");
if (playersList.currentIndex == playersList.maxNbPlayers) return false;
playersList.players[playersList.currentIndex].nickname = name;
playersList.currentIndex++;
return true;
}
As you can see, when the server is created, it sends to himself its nickname threw the gameobject containing the players data. Then when a players connects to this server, it sends its nickname too, but the gameobject is not updated in the server's scene ! I don't understand why ...
Answer by KiraSensei · Oct 11, 2012 at 09:14 PM
I found the solution bu myself. That was quite a stupid problem actually ...
The clients were reading their own playersList variables (and this is normal). I have to give specifically the players names from the server only to the clients threw RPC method. Then it works.