수정중인 페이지 입니다.
fusion | v2 switch to V1  

Network Runner

Overview

NetworkRunner is Fusion’s central Unity component which represents a single networked Peer. All messaging, matchmaking, connecting, spawning, simulation and state replication are orchestrated by this component. Multiple Network Runner instances can be run in a single Unity instance, with each Network Runner GameObject instance representing an individual peer. See Multi-Peer.

Usage

Creation

This Network Runner GameObject can be created in three ways:

  • As an instantiated Prefab at runtime
  • Loaded As a Scene Object
  • Dynamically created at runtime by adding NetworkRunner component to a GameObject

Startup and Connecting

Once created, a Network Runner instance can connect to matchmaking, or can create/join a Room.

Creating or Joining a Room

Calling StartGame() from a NetworkRunner instance creates a Peer, which joins or creates a room as specified by the StartGameArgs argument. In Single Player Mode however, no connection to the Photon servers is made, and no Room is created.

In Multi-Peer Mode, all Scene Objects and Spawned Objects are made children of a dedicated GameObject, and are added to the PhysicsScene/PhysicsScene2D associated with that Runner.

IMPORTANT: You can only use a NetworkRunner once. Once that NetworkRunner disconnects from a game session or fails to connect it should be destroyed, and a new Network Runner instance should be created to start any new game sessions.

Runner Support Components

On startup, the NetworkRunner component will find and register all child SimulationBehaviour components. These components will receive FixedUpdateNetwork() and Render() callbacks.

The NetworkRunner also finds all child INetworkRunnerCallbacks interfaces in the Components on the game object, and registered them for callbacks.

Built-In Fusion Runner Components

There are a number of Fusion components that can be added to the Network Runner game object which extend the Runner's functionality.

  • HitboxManager - Automatically added at Runtime and manages Hitboxes and Hitbox history. See Lag Compensation.
  • RunnerLagCompensationGizmos - Add these to enable Lag Compensation gizmos.
  • RunnerAOIGizmos - Add this component to enable Area Of Interest gizmos. See Interest Management - Area Of Interest.
  • RunnerEnableVisibility - When added, Runner Visibility is enabled for Multi-Peer mode, and all Scene and Spawned GameObjects are registered for Visibility handling. Needed for the Runner Visibility Controls window to work. See Multi-Peer and FusionRunnerVisibilityControlWindow.

Custom SimulationBehaviours Runner Components

You can make your own Runner-specific support components by adding a SimulationBehaviour derived class or component implementing INetworkRunnerCallbacks (or both in the same Component) to your Network Runner game object.

These components will automatically be found by the NetworkRunner instance when NetworkRunner.StartGame() is called, and the associated callbacks will be called when applicable.

Custom INetworkRunnerCallbacks

On startup, the NetworkRunner component will find register all child components with INetworkRunnerCallbacks. See INetworkRunnerCallbacks API Reference.

NOTE: Some callbacks may not be applicable and will not be called, due to order of execution. For example, OnPlayerJoined() will not fire for previously joined Players, or the Runner's own player (as they will already be joined by the time these callbacks are registered).

NetworkRunner in the Hierarchy of Core Objects
The NetworkRunner manages all Connection, Matchmaking, Messaging, Event Callback, Snapshot Memory and Network Object synchronization.

Player / PlayerRef Struct

Except in the cases of the Dedicated Server or the Shared Mode Game Server, all peers are assumed to represent human player(s) who are providing inputs. As such, each NetworkRunner has an associated PlayerRef struct value.

The local PlayerRef value is returned by Runner.LocalPlayer. For the cases where there is no Player (Dedicated Server or Shared Mode Game Server), the value is PlayerRef.None.

The PlayerRef is used to indicate which Peer has Input and State Authority of Network Objects and is used for targeting Peers with Remote Procedure Calls.

Network Connection

Connections and transport handling for peer is wrapped by the NetworkRunner. It handles connections to the Matchmaking Servers, Room Servers and Game Server.

Matchmaking

See Matchmaking.

Tick Management

The NetworkRunner is responsible for determining when Ticks need to be simulated and re-simulated. Every Unity Update, the NetworkRunner determines how many Ticks need to be simulated, based on the amount of time that has past since the previous tick simulation.

Additionally, Clients in a Room continuously receive telemetry from the Server to regulate how far ahead of the server they should be ticking. Clients speed up and slow their tick rate as needed over time, to ensure sent tick updates reach the server prior to it needing them.

When a Tick is simulated, Fusion calls all FixedUpdateNetwork() callbacks, as well as a number of other Event Callbacks related to simulation.

Network Object Management

The Network Runner manages the lifecycle of Network Objects, replication, scene management, and all networking and Network Object related callbacks.

Spawning

See Network Object Spawning.

Scene Management

See Scene Management.

Physics Scene

In Multi-Peer Mode each Runner has an associated Unity PhysicsScene and/or PhysicsScene2D, into which all Scenes and Spawned objects are loaded into. You can Get these Scenes using Runner.GetPhysicsScene() and Runner.GetPhysicsScene2D() respectively.

Interest Management

See Interest Management.

Event Functions

All NetworkBehaviour events and timing segments originate from the NetworkRunner component. See Network Behaviour Event Functions and Callback Interfaces.

SimulationBehaviour virtual event callback methods:

  • FixedUpdateNetwork()
  • Render()

NetworkBehaviour exposes these virtual event callback methods in addition to the above SimulationBehaviour callbacks:

  • Spawned()
  • Despawned()

Additional NetworkRunner event callbacks can be added with these interfaces such as:

  • IAfterSpawned
  • IBeforeAllTicks
  • IAfterAllTicks
  • IBeforeTick
  • IAfterTick
  • IPlayerJoined
  • IPlayerLeft

See Network Behaviour Callback Interfaces for a more complete list of Event Callbacks.

기술 문서 TOP으로 돌아가기