- Home /
Using Server to initialize Stuff on the client [UNET]
Hi, for my game I have different settings on how to play the game. When the game is played in multiplayer modus, the settings of the host are used for all players. Therefore when the game starts, all values from the host should be applied on the Clients. I'm using the following approach (The Class of course has NetworkBehaviour and is attached to a gameobject in the game scene):
ParameterClass LocalParameters;
public override void OnStartServer()
{
base.OnStartServer();
LocalParameters=GetParameters();//Method which gets parameters from Host Settings;
RpcInitialize(LocalParameters);
}
[ClientRpc]
void RpcInitialize(ParameterClass HostParameters)
{
LocalParameters= HostParameters;
}
Unfortunately the Rpc Methods never get called on the clients. Probably because the clients are not ready when the server already is. Which is the best method to initialize the clients with values from the host?
Similar problem as here but solution doesn't work for me http://answers.unity3d.com/questions/1212084/clientrpc-not-working-540b24.html
EDIT:
I tried out this and it seems to work. But I don't know if it is the most elegant solution:
[SyncVar]
ParameterClass LocalParameters;
public override void OnStartServer()
{
base.OnStartServer();
LocalParameters=GetParameters();//$$anonymous$$ethod which gets parameters from Host Settings;
}
public override void OnStartClient()
{
Debug.Log(LocalParameters);
}
Your answer
Follow this Question
Related Questions
How to fix "ClientRpc call on un-spawned object" error, using UNET 2 Answers
Standard ClientRPC not called on client 1 Answer
how to ask Server for a value? 1 Answer
Networked Objects not appearing on Client when Client loads scene first 1 Answer
How do you Change Color or any variable of non-player object on both client and server in uNet 0 Answers