- Home /
Can I use RPC calls in an Update function ?
Hey, i'm making a multiplayer game, and i got the logic working fine.
I used RPC calls for every thing, but i don't know if it's the right way to do it.
Can i use RPC calls sending the player position and lookDirection for all the other players in an Update function?
Or do i need to use some other way?
What i want to do is just send some informations of all players to all players in the update function (or some thing fast enough to pass position and rotation) in the same script, like an RPC call for every one passing these values.
Thanks in advance.
Answer by asafsitner · Sep 24, 2011 at 09:07 PM
You can send a RPC in Update(), but it's highly not recommended. Instead, have the networkView watch the script and use OnSerializeNetworkView() for state sychronization. (or, if you're just synchronizing rotation and position, have the networkView watch the Transform itself)
If you find the network send rate too slow, you can change the send intervals in the network settings through Edit -> Project Settings -> Network
I use RPC calls in the update loop for sending player actions- like jumping or attacking. Location and velocity information, though, should be synchronised with OnSerializeNetworkView().
@syclamoth yes, that is true. However, one needs to be very careful about the RPC buffer - sending, say 30 buffered RPCs per second (game @30 FPS) can cause huge problems, as some of them are almost guaranteed to be lost in the way, which will cause the buffer to swell with waiting RPCs. Could lead to very entertaining results. :)
But do i need to use a networkView in every multiplayer character? or i can send all data in one networkView? Sorry, but i didn't understand how exactly OnSerializaNetworkView works, even with the docs :/
I have my fps character controller, and i need to pass the informations of this player to every one, that will update the 3rd person view of my character in their scene... there is something like, link a networkView to an other one?
Basically you need a networkView for everything that you want to sync over the network. I presume you'd have one as part if your player prefab, however, so you won't need to manually attach those.
In the OnSerializeNetworkView() method you make the check to see if you should read to the network or write from the network, so you know whether to update other players or your own.
Your answer
Follow this Question
Related Questions
Rpc client issue 0 Answers
[2D] Get the position of an object outside the scope 2 Answers
Call an RPC to a specific client 1 Answer
How to change GameObject Material over Network! 0 Answers
Transfering vars to RPCs? 0 Answers