Working on a project where each player can see their own units in detail and only limited or no detail of their opponents units. Essentially a fog-of-war.
The server has all ‘real’ GameObject units on it. It also has the fog-of-war view of each player - opponents units are represented by stand-in GOs that contain less information than the ‘real’ GO. So, with 2 players, there are 4 hierarchies:
RedTeam Units
BlueTeam Units
RedTeam’s View of other units
BlueTeam’s View of other units.
I am playing ‘hotseat’ right now where I can press a button to change render views to see from Red or Blue perspective using Render Layers to limit drawing.
How (if at all) would I use Network.Instantiate to do the same thing on multiple clients, given that it instantiates and syncs on all clients? I want Red Player to see only RedTeamUnits and RedTeamView. Obviously I could just limit visibility like I do in hotseat, but if at all possible I don’t even want to send data about BlueTeam and BlueTeamView to the Red client.
If this is not possible with Network.Instantiate, how else do you do it? More specifically, how do you send specific sync states to a subset of clients?
BTW, this is a fairly slow paced game so FPS level of network performance may not be crucial.
You are right that Network.Instantiate is not going to work very well. Also, if you can only see the units you are supposed to see, then something has to decide that. That sounds an awful lot like an authoritative server which sends updates based upon visibility.
Exactly. I currently have the code working for determining visibility on the server. Just not sure how to send one set of data to one client and different set of data to another client. I’m sure this is pretty basic.
Maybe roll my own Network.Instantiate that broadcasts ‘create instance’ RPCs to all clients but have a client ignore it if it is not relevant.
That authoritative server would have to check visibility and then give the right players the updates. If the object disappears from view, then it should also be told to the players that cannot see it that it has disappeared from view in which case they will no longer display it. Maybe just toggle it as invisible/inactive locally until it is updated again as being active/visible or explicitly destroyed.
How do you tell one player different information than you tell to other players? Is it something like this:
Server sends RPC to all players that unit RedA is no longer visible to player Blue.
all players except Blue receive but ignore this message
Blue sets a flag on it’s local copy of RedA that it is invisible (or just destroys it’s local copy of RedA?)
Server continues sending RedA OnSerializeNetworkView data to all players,
Blue ignore updates to RedA if local invisible is true
a follow-up - if RedA is never Instantiated on the Blue client, what happens to OnSerializeNetworkView for RedA sent to client Blue? Is there an error or is it just ignored?
Network.Instantiate has very limited use, if you instantiate and uninstatiate these objects it will be fine as long as nobody reconnects. If you plan to let players join a game in progress, you need to minimize the use of instantiate.