When to use OnSerializeNetworkView and RPC's

Hey,

I searched for some information on typical situations when to use RPC’s over OnSerializeNetworkView but I couldn’t track down any information.

I just wanted to know in what situations is it best to use an RPC over OnSerializeNetworkView and visa versa. In a tutorial im following at the moment he is using OnSerializeNetworkView for tracking player movement and then RPC’s for things like pickups, but in another tutorial he was using RPC’s for movement, is there a standard for which method to use for different situations?

Thanks :slight_smile:

To be honest, there is no right way and no wrong way. The different approaches have different strengths and weaknesses.

RPC

This will trigger a function on a device connected to the game, you can use the call to send to a specific player, everyone but your self or everyone. This call can be triggered no matter if the Networkview is your own or if it belongs to one of your other players. One good thing about this is that it will not use any traffic unless you actually call a method with RPC but you should stay away from using it every frame. Another good thing about RPC is that you always get the calls in the right order but if you make too many calls your whole game will be delayed due to this in a slower network (or with many players).

I personally use RPC when letting other users interact with a rotating sphere at the same time as myself in my game.

The most obvious time to use RPC is when you are setting states in your game and applying damage or health. Those one time calls should always be performed with an RPC call. The reason is simple, you dont want unnecessary traffic in your game to steal bandwidth. If you would have done this with the Serialize method the values would only be one way (from owner of the networkview to the other clients) and you would have this sent each network tick (standard 15 ticks per second).

Serialized

This has the benefit of being synced at a specific rate and you can set if it is going to wait for previous packages or not. The documentation does a good job of describing the different modes. http://unity3d.com/support/documentation/Components/net-StateSynchronization.html

The serialized would be great for something like an enemy that needs to transfer its position to the other network players. I use this for a zombie type of enemy (a different game then the sphere) right now and i decided to sync a script that just handles the movement over network. The only thing I need to sync is the position and rotation of the enemy at a set rate (since it will be changing all the time I prefer the Unreliable mode). My script then Lerps between the current position and the new position and rotation that arrive from the networkview.


Im sure there are more people out there who have more tips and tricks that they use for their specific games and this is just my experience and advice. If you have any more specific scenario I could give you my opinion for that also.