Finally understanding SetSendingEnabled and networkView.group

So I’ve read a ton of posts around SetSendingEnabled and networkView.group and I still see a lot of confusion. I want to try and clarify what I’ve discovered and how I believe it works, and also ask if anyone from Unity (or any networking guru) can comment on the one flaw I’m still encountering. I’d appreciate any feedback.

So it wasn’t obvious at first as I thought I could use a combination of setsending… and network group to control who I was sending commands to. For example I have a multi player game and at any time players can be active in different levels. Therefore, I only want to send commands to other player in the same level as me. Anyone in a different level doesn’t need to know what I’m doing.

I originally was going to recreate the player in each level, and not have the player exist in the other levels but this didn’t work due to the networking expecting every client to properly receive updates.

Then I chose to use DontDestroyOnLoad and properly toggle the player hidden/visible as players move between levels. This works just fine. The only issue is that I’m still sending network updates to all the clients, which isn’t efficient when I’m sending updates to clients in a different level. I’m updating a player who’s hidden and not seen by them anyway, so why do it.

To optimize things I wanted to say don’t send any position updates or RPC’s to other clients not in the same level as me, so when I load a level I thought I’d use a network group per level to separate the traffic. As I leave a level I turn off sending for that group and when I enter a level I turn on sending for the new level. I then update my local networkView.group to the new level.

Now I had believed that if my player was set locally to group 5, and I have setsendingenabled for group 5, I would send the message and only other clients in group 5 would receive it. No that’s not the case. What happens when setsendingenabled and networkView.group are equal, then you are permitted to send a request. If on the other hand they didn’t match and you issue an RPC or a sync update, it’s just ignored (as near as I can tell). All clients apparently will receive the request. So if I have a client in level 1, and player 2 is hidden because player 2 is in level 5, I thought I could block sending updates about player 2 to client 1, since they’re in different levels. Unfortunately, as long as player 2 (in level 5) is able to send updates (his group matches the setsendingenabled) all the remote avatars of that player will receive the update, no matter what level they’re in. This was not the behavior I expected, and the documentation is very unclear, but I guess it makes sense.

Unfortunately, I haven’t found a way to isolate traffic to just specific clients. I think a lot of us want a way to SetReceivingEnabled(group, bool) instead of just for a player granularity, so we could disable a client from receiving any updates from another group of clients, based on groupid. So far I haven’t found anything like this.

If any of our Unity developers or Networking gurus out there have a clean solution, or want to challenge any of my findings I’d be happy to hear your thoughts.

In short what I want and I suspect many others, is don’t update my remote avatar when the remote client is in a different level. This is a wasted network update, and we’re trying to optimize our network traffic.

Thanks all

I have the same need for a project I’m working on. I was hoping groups were the solution but seemingly no.

Have you tried storing a list of Player network IDs in each room, and then using NetworkView.SetScope? I think I’m going to give that a shot today