I am beginning my networking journey and have a question about buffered RPCs. Specifically, is there any way to control when the buffered RPC calls actually occur on a newly joining client?
Suppose my RPC relies on another reference being set (e.g. I instantiate a particle emitter on my character in Start) and my RPC is telling that particle emitter to emit a particle. For all clients already connected, this is fine, but a newly-connecting client will receive this call before his particle emitter has been instantiated, thus throwing a null reference exception.
Is there a better way around this problem, or do I just have to be that much more careful when designing systems to work with networking?
Be very careful, that would be my advice.
There are various ways of controlling the sending and receiving of RPCs. In my experience over the last 4 days none of them would do what I wanted. Some observations, which I'd suggest verifying yourself, I don't guarantee all of this is 100% accurate, I did a couple of late nights.
`Network.SetSendingEnabled` - This allows you to disable sending of data over RPCs by group number or a combination of group and `NetworkPlayer`. As far as I can tell any calls made before you call this are still sent when a client joins. I'm not 100% on this at all, I didn't test extensively but I was deffinitely getting some RPC calls on my client when it first connected, and I was calling `SetSendingEnabled` false for that client in the OnPlayerConnected on my server. I also tried setting this false for a group and then just enabling it on individual clients once they were up to speed but they were still getting old RPC calls when they connected. I thought maybe setting the group false would default new clients to false, but that didn't appear to be the case.
`Network.SetReceivingEnabled` - This allows you to disable receiving of data over RPCs by a combination of group and `NetworkPlayer`. Note that, for this one, the system sending the data to whichever client you have this disabled on will keep sending data/RPCs. The client will just ignore them. This is not useful if you actually just want to do something first before you handle the RPC call, because the call was still made, the client just ignored it.
The result being, that as far as I can tell, there is no way to pause the buffered rpc calls in a satisfactory manner for handling new clients (in my case at least anyway). I do intend to do more testing to verify some of these things but I'm not going to have time for at least another week.
I gave up on Unity's Buffered RPCs halfway through the 4th day. I switched to using non Buffered RPCs and my own buffering layer (I also wrote my own versions of `Network.Instantiate` and `Network.Destroy` as they use Buffered RPCs) and I had it up and running by the end of the afternoon. Join in progress working! yay.
I may have been missing something but I couldn't find any advice searching the forums related to using Buffered RPCs for this sort of thing, most of the posters weren't using them. I think they're good for simple senarios, but past the basics you need to create something a bit more flexible.
[edit: there's also NetworkView.SetScope, I didn't try it, the documentation to me suggested it was more for state synch messages than RPCs]