Search Unity

Entity Management

Discussion in 'Multiplayer' started by meinboi, Jul 20, 2009.

  1. meinboi

    meinboi

    Joined:
    May 13, 2009
    Posts:
    54
    Any idea how this is done in Unity? It seems that Unity's state sync cannot be turned on or off for certain players.

    If a player's at the other side of the world, i don't need all information synchronized.
     
  2. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    See

    http://unity3d.com/support/documentation/ScriptReference/Network.SetReceivingEnabled.html

    Although the docs don't go into much detail on this method, the point is, you need to keep a queue of player positions, then locally check that queue for any player within range of a certain radius, if they are not in range based on the queue, disable the receiving from that player, otherwise enable it. You will still require one broadcast that is always enabled that gives the simple x,y,z coordinates of the player to determine if they are in range to start receiving the rest of the information.
     
  3. SixTimesNothing

    SixTimesNothing

    Joined:
    Dec 26, 2007
    Posts:
    167
    It would also be worthwhile looking into the documentation for NetworkView.SetScope...

    http://unity3d.com/support/documentation/ScriptReference/NetworkView.SetScope.html

    This is how I did it in my project. This also allows you to set the scope for NetworkViews attached to non-player entities - i.e. NPCs which are controlled by the server. I could be wrong, but I'm pretty sure Network.SetReceivingEnabled can only be used to define which messages are received for players, rather that any state synchronisation event or RPC from any NetworkView.
     
  4. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Actually I would definitely use SetScope for this, and not SetReceivingEnabled, as SetReceivingEnabled will not prevent the messages to be sent to your client. If you don't have the relevant objects on your client (which I would avoid) you'd even get error messages.

    SetScope on the other hand makes it possible to disable sending the messages on the server which will give you all the benefits you need (in particular: a lot less network traffic).

    One very unfortunate thing about SetScope is that it has no effect on RPCs - only on the built-in NetworkView synchronization (if that was considered a bug and fixed by now, someone please correct me ;-) ).

    For RPCs, you can use

    http://unity3d.com/support/documentation/ScriptReference/Network.SetSendingEnabled.html