This document is about: FUSION 2
SWITCH TO

Area of Interest in Fusion Shared Mode

This page accompanies the Photon Fusion 2 Area of Interest Tutorial: Sync Only What Each Player Needs video and explains how to set up Area of Interest (AOI) in Photon Fusion 2 so each player only receives state updates for the NetworkObjects that are relevant to them.

Use this page when a scene has many NetworkObjects and a given player only cares about part of the world. It uses a top-down Shared Mode sample.

For the full API reference, see the Interest Management manual page.

Photon Fusion 2 Area of Interest Tutorial: Sync Only What Each Player Needs

Overview

Area of Interest restricts which NetworkObjects a client receives updates for. Each player registers one or more regions in the world. Fusion divides the world into cells and only replicates a NetworkObject to a player if the object's position falls inside one of that player's cells. Objects outside a player's interest stop receiving Networked Property updates and RPCs on that client, which reduces received network traffic in large scenes.

AOI does not decide what your game does with an object that leaves interest. You decide whether to hide, freeze, or fade it, and what happens when it comes back.

The video covers:

  • enabling Interest Management in the Network Project Config;
  • registering a player AOI with Runner.AddPlayerAreaOfInterest and updating it as the player moves;
  • why only the State Authority updates the AOI in Shared Mode;
  • how the AOI cell grid works, and why the requested area and the actual cells do not match exactly;
  • setting Object Interest to Area Of Interest on a NetworkObject;
  • using the Interest Enter and Interest Exit callbacks to show and hide objects;
  • why the Shared Mode Master Client always sees the objects it has State Authority over;
  • checking received network traffic with Fusion Stats.

The sample has one player and around 100 constantly moving networked entities.

Video Timeline

Time Section
00:00 Intro: What AOI Does
00:20 Understanding Area of Interest (AOI)
02:06 Enabling Interest Management in Fusion
02:48 Setting Up the Player's Area of Interest
03:44 Creating the AOI Entity Spawner
05:57 Creating AIEntity.cs and Random Movement
06:48 Handling Interest Enter and Exit Callbacks
08:10 Setting Up the Network Entity Prefab
09:15 Setting Up the Camera and AOI Visualizer
09:30 Testing the Sample in Unity
10:42 Testing AOI with Multiple Players
11:40 Measuring Network Bandwidth with Fusion Stats

Enabling Interest Management

  1. Open the Network Project Config.
  2. Under Replication Features, enable Interest Management. In the current manual this option is named Scheduling and Interest Management.

Area Of Interest handling stays disabled until this setting is on. The sample runs in Shared Mode.

Creating the Player AOI

Create a script called AOIPlayer and add it to the networked player prefab. It tells Fusion where the local player is and how large the player's Area of Interest should be.

Call Runner.AddPlayerAreaOfInterest and refresh it as the player moves. The size parameter controls how large an area around the player Fusion considers.

In Shared Mode, only the client with State Authority over the player object updates the AOI. Adding a new AOI for a player replaces the previous one, because Shared Mode supports a single AOI per player.

C#

using Fusion;
using UnityEngine;

public class AOIPlayer : NetworkBehaviour
{
    public float Radius = 20f;

    public override void FixedUpdateNetwork()
    {
        if (!Object.HasStateAuthority)
        {
            return;
        }

        Runner.AddPlayerAreaOfInterest(Runner.LocalPlayer, transform.position, Radius);
    }
}

Visualizing the AOI

AOIVisualizer is only part of the sample. It does not control networking. Add it to the player and give it a reference to AOIPlayer. It draws two things:

Visual Meaning
Cyan square The AOI requested around the player.
Green squares The AOI cells Fusion is actually using.

Fusion divides the world into cells internally, so the requested square and the final networked area are not always the same. An object can still receive updates when it sits slightly outside the cyan square if it is inside a green cell.

Creating the Networked Entity

Create an entity prefab that AOI can manage.

  1. On the root, add NetworkObject, NetworkTransform, and AOIEntity.
  2. On the NetworkObject, set Object Interest to Area Of Interest.
  3. Create a child called Visuals and put the visible model inside it.
  4. Assign that child to the Visual Root field on AOIEntity.

NetworkTransform provides the position Fusion uses to decide which AOI cell the object belongs to. Any NetworkObject taking part in AOI needs a NetworkTRSP-derived component, such as NetworkTransform, on the same GameObject as the NetworkObject.

The networked object stays active at all times. Only its visuals are enabled or disabled.

Creating AOIEntity

In the sample, AOIEntity does two things:

  1. If this client has State Authority over the entity, it moves the entity randomly around the level.
  2. It implements Fusion's IInterestEnter and IInterestExit callbacks. When the local player gains interest in the entity, it shows the visuals. When the local player loses interest, it hides them.

C#

using Fusion;
using UnityEngine;

public class AOIEntity : NetworkBehaviour, IInterestEnter, IInterestExit
{
    public GameObject VisualRoot;

    public override void Spawned()
    {
        // InterestEnter is not called on spawn, so show the visuals here.
        VisualRoot.SetActive(true);
    }

    public void InterestEnter(PlayerRef player)
    {
        VisualRoot.SetActive(true);
    }

    public void InterestExit(PlayerRef player)
    {
        VisualRoot.SetActive(false);
    }
}

These callbacks fire on a client only for interest changes related to the local player. They are not called when the object spawns or despawns on a client, so handle those cases in Spawned and Despawned.

Spawning the Entities

Create AOIDemoEntitySpawner, add it to the scene, and assign the entity prefab. The sample spawns around 100 entities across a large area.

The Shared Mode Master Client spawns the entities, holds State Authority over them, and moves them. This gives the test a large number of constantly moving NetworkObjects.

Testing the Sample

  1. Start two Shared Mode clients and join the same session.
  2. The Master Client spawns and controls the entities.
  3. Use the non-Master client to see AOI. Move its player around the map.
  4. The cyan square follows the player and shows the requested AOI. The green squares show the cells Fusion currently uses.
  5. Entities become visible as their cells enter the player's interest and disappear as those cells leave interest.

The Master Client has State Authority over the entities, so it keeps seeing them outside its own AOI. For this sample, the non-Master client is the one that shows the culling.

Checking Fusion Stats

Open Fusion Stats on the client and look at the received network traffic while the entities move.

Without AOI, the client receives updates for all of the objects. With AOI enabled, Fusion only sends updates for objects currently relevant to that player. As the player moves, different entities enter and leave interest. The saving grows with the number of NetworkObjects that sit outside a player's region.

Key Concepts

Concept Description
Interest Management Fusion's data culling features, set up through the Network Project Config's Replication Features.
Area of Interest (AOI) A region registered per player; objects inside it are replicated to that player.
Runner.AddPlayerAreaOfInterest Registers a player's AOI region from a position and size. Call it again as the player moves.
AOI cells The internal world grid Fusion uses, so the final area differs from the requested square.
Object Interest Per-NetworkObject setting: Area Of Interest, Global, or Explicit.
NetworkTRSP Base class providing the position AOI uses; NetworkTransform derives from it.
IInterestEnter / IInterestExit Callbacks raised when the local player gains or loses interest in an object.
State Authority In Shared Mode, the client that owns the object; it keeps seeing its own objects.
Fusion Stats Overlay used to compare received network traffic with and without AOI.

Best Practices

Use this checklist when adding AOI to a project:

  • Enable Interest Management in the Network Project Config before testing, or AOI has no effect.
  • Set Object Interest to Area Of Interest on every NetworkObject that should be culled.
  • Put a NetworkTRSP-derived component such as NetworkTransform on the same GameObject as the NetworkObject.
  • In Shared Mode, update the player's AOI only from the client with State Authority over the player object.
  • Remember that Shared Mode supports one AOI per player.
  • Decide what happens to out-of-interest objects (hide, freeze, fade) and what happens when they return.
  • Keep the networked object active and toggle only its visuals.
  • Handle the initial state in Spawned, because InterestEnter is not called on spawn.
  • Test culling on a client that does not have State Authority over the objects.
  • Compare received traffic in Fusion Stats to confirm the effect.

Common Pitfalls

Pitfall Why It Is a Problem
Interest Management left off in the Network Project Config AOI handling is not enabled, so nothing is culled.
Object Interest not set to Area Of Interest The object is not governed by player AOI regions.
No NetworkTransform (or other NetworkTRSP) on the object Fusion has no position to place the object in a cell.
Updating the AOI from clients without State Authority Only the owning client should register the player's region in Shared Mode.
Judging the result from the Master Client It owns the entities and keeps seeing them, so no culling is visible there.
Expecting objects to disappear exactly at the cyan square Fusion uses whole cells, so objects near the edge may still be replicated.
Disabling the whole networked GameObject on interest exit Only the visuals should be toggled; the networked object stays active.
Relying on InterestEnter for the first visibility state It is not called when the object spawns on a client.
Nested NetworkTransforms under non-networked parents Local position is used as the global position for AOI; use AutoAOIOverride.

Summary

AOI limits replication to the NetworkObjects inside regions each player registers. In this sample, AOIPlayer registers the region with Runner.AddPlayerAreaOfInterest from the client with State Authority, AOIVisualizer shows the requested square and the cells Fusion actually uses, and AOIEntity shows or hides its visuals from the interest callbacks.

The Master Client owns the test entities and always sees them, so culling shows on the non-Master client. Objects outside interest stop receiving updates there, and Fusion Stats shows the effect on received traffic.

Last updated on

Back to top