- Home /
Temporarily hold Buffered RPC call
Hey guys, I'm making a multiplayer game. It has a lobby on the menu, where the client connect to server to get informations, and then, when the client click "Join" it loads the level and play. The problem is: i'm using the Network.Instantiate function to create the players on the game, and i've notice that Network.Instantiate uses a buffered RPC call, so when i connect on the lobby, it instantiate the players, but i need it to happen just when the player get with the level loaded. Any one know how to temporarily hold a buffered rpc call, so when i finish load the level (i already have a function for that) it let the RPC calls be executed?
Thanks in advance.
see the networking example provided by unity....
There is an object that sends a message (OnNetworkLoadedLevel) to all objects in game.. the spawnPlayer object receives that message and only then it spwans the player...
Answer by syclamoth · Sep 27, 2011 at 12:15 AM
Instead of instantiating your players immediately when they join, why don't you use Network.Instantiate upon level loading? There's no need to instantiate things as soon as players connect, since you can just store a list of players in some gameEngine object that keeps track of this stuff until your game actually begins, at which point you can instantiate everything at once, and be sure that all players will get the message at the same time!
the problem is that unity automatically instantiate the player prefabs when it connect to one server, because it use a buffered RPC call
Unity isn't doing anything like that automatically. Your player prefab is instantiated by one of your scripts. Beside that I really don't like Network.Instantiate especially because of the buffered RPC. I never use any buffered RPC since you almost can't control the removal of them.
In our Hack&Slash game i use only one NetworkView and it's placed on a manager object in the scene. All communication we do over this NetworkView. The clients use normal RPCs to send information to the server and the server distributes the information via OnSerializeNetworkView and normal RPCs.
You can use Network.Instantiate if you can live with it's drawbacks.
I personally never use Network.Instantiate if I can avoid it- the automatic buffering is pretty annoying. I use Network.AllocateViewID() and then send RPC functions which make sure the NetworkViewIDs stay the same on instantiated objects (which basically does the same thing, but with more control over buffering). To be fair, Network.Instantiate is, however, much easier to use.
Thanks, i'm using the Network.AllocateViewID() and passing it in RPC (not buffered) for the players... and when a new player connect, the server send all viewIDs to the new player.