RPC Buffer question

Hi all, I’m just starting with Unity3D and got a problem that I don’t really understand (after reading the script reference and stuff)

1 - I Network.Instantiate a GameObject “myObj” (with networkView, of course) on the server and set a variable (playerNumber) to 0.
2 - I connect with a client and Network.Instantiate another “myObj”, now in the client, and set playerNumber to 1.

Question 1 : the playerNumber wont be synchronized, correct?

Assuming Q1 is correct, I did the following:

3 - I implemented
[RPC]SetPlayerNumber(int val) { playerNumber = val; }
, and instead of setting the value, I call networkView.RPC(“SetPlayerNumber”, RPCMode.AllBuffered, new object[ ]{number});

Now the playerNumbers are correct in the server, but the client doesn’t know playerNumber of the server…

Problem 1: If I connect a second client in this scenario, it won’t start the playerNumbers of the other instances (Server and Client 1)…

I’m using the playerNumber to set a color to the character, I’m gonna try to put a screenshot to demonstrate the problem.

I thought the “Buffered” RPCMode did just that, when a new client connects, all the RPCs buffered would be called again in the new client…

Any ideas?

Thank you in advance.

An RPC is undirectional, so you have to send an RPC back to get a return value.
Or send it to the server and make sure the server updates all the clients.

I found a script on a GameObject on the scene that makes a Network.Instantiate() on the Start()…
So the server loads the scene and Network.Instantiates (lets say, objectA) correctly…
When the client connects, it loads the scene and Network.Instantiates (lets say, objectB), so that the server sees objectB, but the client doesnt see objectA…
A way to solve this is to reload the scene, so the scene gets reloaded on both players and the Start() occurs again, but I’m trying to avoid that…
Is there any way to tell the client that an object has been Network.Instantiated before he connected?

Thats what Network.Instantiate does, it’s a buffered RPC call. If it doesn’t work you probably have some other code that prevents that.

Thought so… but i really cant figure out what is preventing that… Any thoughts?

There is one instance of InitObjectwith an InitScript that on Start() does a Network.Instantiate(PlayerData) in the scene;
Server loads scene =>
[OnServer] 1 instance of InitObject(id=1), 1 instance of PlayerData(id=11)
Then…
Client connects and loads scene =>
[OnServer] 1 instance of InitObject(id=1), 2 instance of PlayerData(id=11 id=12)
[OnClient ] 1 instance of InitObject(id=2), 1 instance of PlayerData(id=12)

Notice that the script that originates PlayerData(id=11) dont exist on the client, i guess the Network.Instantiate doesnt references the origin of the call but, could this be the problem?

Oh didnt see that…
Yeah, the number assignment is like
Client sends an RPC request of the number to server (through a Network.Instantiated with a networkView object) , server sends back an RPC to all with the value…

You will need to keep a list on each instance that holds the player number with a reference to the player for that to work.

Hmm ok… I appreciate the help, gonna keep trying… if I find my mistake, I’ll post it here…
Thanks =]

Odd… i just put a DontDestroyOnLoad(this) on the PlayerData Start() and it’s working fine now…
Is it possible that the buffered RPC call made it to the client, but the loading scene destroyed the object being RPC instantiated ?
Btw, I’m not calling Application.LoadLevel(xx) on OnPlayerConnected anywhere…