- Home /
How to Send RPC from One Client to anther while the server isn't in the same scene
i'm Developing a multiplayer game with dedicated server.
can i send rpc from one client to anther while the dedicated server isn't in the same scene with them?
Can you be in a different scene to a dedicated server and still be connected?
I'd like to know if this is possible as well. Suppose you had a game where players could be in the same or different scenes. Seems like you would need a different server for each scene, if the server(s) are authoratative.
Answer by asafsitner · Dec 07, 2011 at 11:13 AM
Yes, you can.
The client and server can be on two different scenes, it doesn't matter. They can even be in two completely different projects.
As long as there is an object on the client that has a script with the same RPC (doesn't have to be the same script, only the signature needs to be the same).
Hey, can you be more specific about what you mean by the signatures need to be the same? Is it function signatures or...?
Function signature, yes. RPCs are sent from a NetworkView
component to a NetworkView
component of the same viewID
, regardless of what the receiving object actually is, so as long as there is an object of the same viewID
on the receiving end and it has a script with a RPC that has the same name and parameters (i.e. signature) the RPC will go through properly regardless of scene or even project.
As you can see this is a huge opening for bugs and frustration so always remember to check your viewIDs
for uniqueness and allocate/re-allocate them as needed with Network.AllocateViewID
. $$anonymous$$eep in $$anonymous$$d though that the last network peer (`NetworkPlayer`) who called Network.AllocateViewID
on a NetworkView
becomes the owner of that NetworkView
so only they can use it to send RPCs and write to the synchronization stream.
Again this is an opening for bugs and unwanted behaviour so remember to validate ownership of NetworkView
s.
Was just reading the post.
I understand the issue and have been looking in to it for a few days now. I'm ai$$anonymous$$g to centralize the master server so the code is not also on the client.
It would be a good idea to clear up the issue, for others to also understand.
You mention an RPC signature, by this do you mean an empty function that is declared for the RPC being available?
For example, this would be the client code?
function sendToServer(){
networkView.RPC("serverRPCCall", RPC$$anonymous$$ode.Server, "$$anonymous$$essage From Client");
}
@RPC
function serverRPCCall(client$$anonymous$$essage:String){
//I'm just here for the signature
}
Correct or Incorrect?
just added this in*
I will do a code test next weekend to check that it works the way I expect. I will post the result and the code, here as an answer.
@superme2012: Yes, that's correct. Both the sending and the receiving side need a function with the signature you want to call.
asafsitner is actually partially wrong in the comment above. It's true that the peer that allocates a ViewID (by calling AllocateViewID or by using Network.Instantiate) is the owner of the object. The owner is the only one who can send state synchronisation informations He has the control of this object.
However everybody can send and RPC on this object to everyone else. NetworkViews just establish the link between remote objects and your own version of this objects. One person is the owner, but RPCs can be send over that link either way. The RPC function itself should check who executes it or on which machine it's executed.
Things like SetPlayerName should only be invoked by the owner of the object. See Network$$anonymous$$essageInfo and RPC for more details.
I made a multiplayer game by using only one NetworkView in the whole game. This NetworkView was owned by the server. It was an authoritative server setup so all information was spread by the server. Clients can only use RPCs to communicate with the server / other clients.
@Bunny83: Strange. I tried that once and couldn't send an RPC through a NetworkView that I didn't own. Can you elaborate more on your setup?
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
How can I send a mouse click to a server using an RPC? 0 Answers
Is server the sender of RPC? 0 Answers
RPC Call problem 1 gameobject 1 prefab 0 Answers
Unity 3d dedicated server 0 Answers