수정중인 페이지 입니다.

Interest Management

Overview

Interest Management is a set of data culling features, which restrict specific networked element updates from the server to specific clients/players. This culling is useful for reduction of network traffic, as well as restricting player access to data (such as team only information).

There are two main data culling mechanisms:

  • Object Interest: Restricts NetworkObject updates from server to specific PlayerRefs.
  • Interest Groups: Restricts specific Networked Property updates from server, on a per PlayerRef / per NetworkObject basis.
Interest Management is only available for the Eventual Consistency replication mode.

EventualConsistency and ObjectInterest enabled in NetworkProjectConfig
Eventual Consistency and Object Interest enabled in Network Project Config.

메인 화면으로

Object Interest

Object Interest determines which players will receive which NetworkObject updates (Networked Properties and RPCs) from the server.

The NetworkObject.ObjectInterest setting controls how Player interest for that object is determined. There are three mode options:

NetworkObject ObjectInterest Options
Object Interest Options

  • Area Of Interest: Only players with an AOI region which overlaps this object's AoiPositionSource in 3d space will be interested in this object.
  • All Players: All players receive updates for this object.
  • Explicit Players: Only players explicitly flagged will be interested in this object.

메인 화면으로

Area Of Interest

The server will use each player’s Area Of Interest (AOI) regions to determine if this NetworkObject is of interest to that player. Player AOI regions are specified by calling the Runner.AddPlayerAreaOfInterest() method.

These regions only exist for one tick, and need to be reapplied every tick. Players may have multiple regions (for example if the player is operating a remote camera). If this object position is inside one or more of a player’s AOI regions, that player will be interested and receive server updates for this NetworkObject.

AoiPositionSource indicates which NetworkAreaOfInterestBehaviour component will be used to determine this NetworkObject's position. If null, then one will be searched for on this Object. NetworkTransform and NetworkRigidbody derive from NetworkAreaOfInterestBehaviour, and are typically what is used for AoiPositionSource.

public class SetAreaOfInterest : NetworkBehaviour {
  public float Radius = 32f;

  public override void FixedUpdateNetwork() {
    if (Runner.IsServer){
      var controller = Object.InputAuthority;
      // Set the controlling players area of interest region around this object
      if (controller) {
        Runner.AddPlayerAreaOfInterest(controller, transform.position, Radius);
      }
    }
  }
}

메인 화면으로

All Players

This NetworkObject is always of interest to all players. This effectively disables Object culling for this NetworkObject, and all players will receive server updates for this NetworkObject.

메인 화면으로

Explicit Players

This NetworkObject is not of interest to any player, UNLESS player interest is specifically added with Runner.SetPlayerAlwaysInterested(). Only players with explicit interest will receive server updates for this NetworkObject.

public class MakeAlwaysInterested : NetworkBehaviour, INetworkRunnerCallbacks {

  // Wire up INetworkRunnerCallbacks for OnPlayerJoined
  public override void Spawned() {
    Runner.AddCallbacks(this);
  }

  public void OnPlayerJoined(NetworkRunner runner, PlayerRef player) {
    if (runner.IsServer) {
      SetPlayerAlwaysInterested(player, true);
    }
  }
}

메인 화면으로

RPCs And Object Interest

Object Interest will also affect delivery of any non-static RPCs, as these are bound to an instance of a NetworkObject. The RpcInvokeInfo return value may be used on the server to detect and handle failures to send do to a player not having interest in the NetworkObject the RPC is attached to.

[Rpc]
public RpcInvokeInfo RpcFoo() {
  return default; 
}

public override void FixedUpdateNetwork() {
  if (Object.HasStateAuthority) {
    var info = RpcFoo();
    int culledCount = info.SendResult.CulledReceivers.Length;
    if (culledCount > 0) {
      //Handling for a target peer being culled from send
      Debug.LogWarning($"{culledCount} receivers culled, possibly due to no Object Interest.");
    }
  }
}

메인 화면으로

Interest Groups

Interest Groups can be used to restrict Networked Property updates to only specific players.

Networked Properties can be assigned to named Interest Groups, and the server will only send updates for these properties to players who have interest in that named Interest Group for this NetworkObject (player Interest Group assignment is per NetworkObject, and is not global).

Note: If a NetworkObject is not receiving updates due to Object Interest, then no member data will be updated either, regardless of Interest Groups.

메인 화면으로

Adding And Removing Player Interest In Groups

Network Properties which are assigned Interest Groups, are by default not replicated to players. There are two ways to assign Player interest in a NetworkObject's Interest Groups.

메인 화면으로

Explicitly Setting Player Interest

Player interest in groups is added and removed on a per NetworkObject basis, using the Object.SetInterestGroup() or Runner.SetInterestGroup() methods.

public class SemiSecretColor : NetworkBehaviour, INetworkRunnerCallbacks {

  // This Networked Property is assigned to the group 'EvenOnly'
  [Networked(group: "EvenOnly")]
  Color SecretColor { get; set; }

  // Wire up INetworkRunnerCallbacks
  public override void Spawned() {
    Runner.AddCallbacks(this);
  }

  // this callback requires this NetworkBehaviour to implement INetworkRunnerCallbacks
  public void OnPlayerJoined(NetworkRunner runner, PlayerRef player) {
    if (runner.IsServer) {
       // Only even numbered Players will be included in the group.
      Object.SetInterestGroup(player, "EvenOnly", player.PlayerId % 2 == 0);
      // or
      Runner.SetInterestGroup(Object, player, "EvenOnly", player.PlayerId % 2 == 0);
    }
  }
}

메인 화면으로

Default Interest Groups

All joining players will start with explicit interest in these groups for this NetworkObject. For any groups not in this list, players must explicitly be assigned group interest for this NetworkObject using the method Object.SetInterestGroup() or Runner.SetInterestGroup() (as shown in the example above).

기술문서 TOP으로 돌아가기