FishNet
This page covers the FishNet integration setup, configuration, and architectural details for the Mono Networking framework in DOTS City Sample.
Installation & Setup
Import Netcode sample.
Download and import the FishNet package.
Add the
CUSTOM_NETWORKscripting define in Project Settings > Player > Scripting Define Symbols.Unpack the
DotsCity/Packages/Upgrades/FishNetPrefabspackage.In the Cull Config, set the calculation mode to Multiplayer Calculate Distance or Multiplayer Camera View.
Drag & drop
FishnetPrefabRootinto the scene. In that root, on thePrefabRootResolvecomponent, click the Resolve Refs button (for new scenes).In the
CityEntryPointobject on the scene, uncheck theAuto Bootstrapoption in theSceneBootstrapcomponent (new scene only).Install the Multiplayer Play Mode package to simulate multiple players locally (optional).
Open the
FishNetDemoscene to test the sample implementation.Note
By default, only the
FishNetDemosample works out of the box with FishNet without extra setup.
Architecture & Component Breakdown
The FishNet adapter bridges the transport-agnostic INetworkService and INetworkTransport interfaces with FishNet’s native ServerManager, ClientManager, and IBroadcast messaging infrastructure.
Components are strictly categorized into player-level prefabs, vehicle-level prefabs, and global/scene services.
1. Player Components (Player Prefab Level)
These components are attached directly to the Player prefab, inherit from FishNet’s NetworkBehaviour, and manage local ownership, input processing, and client interactions:
FishNetPlayerMovementAdapter: Attached alongside
PlayerMovementCoreandNetworkObject. Enables input and movement logic strictly on the owning client (IsOwner) while disabling simulation for non-owning remote proxies.FishNetPlayerRpcTransport: Implements
IPlayerRpcTransportandINetworkBehaviour. Handles vehicle entry and exit requests sent via[ServerRpc](ServerCmdRequestEnter,ServerCmdRequestExit) and broadcasts interactions globally via[ObserversRpc](RpcOnEnteredVehicle,RpcOnExitedVehicle).FishNetPlayerSpawnNotifier: Manages client lifecycle hooks (
OnStartClient,OnStopClient), registers the player instance in the globalPlayerRegistryusingOwnerId, and notifiesPlayerSpawnerBasewhen local instantiation completes.FishNetCullPointAdapter: Attached alongside
CullPointCoreandNetworkObject. Captures local camera view matrices and transmits them to the server via[ServerRpc](SubmitCullPointServerRpc) for server-side ECS interest management, handling cleanup upon client despawn.
2. Vehicle Components (Vehicle Prefab Level)
These components are attached directly to synchronized Vehicle prefabs to manage network ownership, synchronization variables, and driver inputs:
FishNetNetworkVehicleObserver: Attached to vehicle prefabs alongside
NetworkObject. ImplementsINetworkVehicleObserver, synchronizes unique vehicle IDs viaSyncVar<int>, and triggers client-side spawn/despawn hooks inMonoVehicleNetworkSyncBase.FishNetVehicleInputSyncAdapter: Attached to controllable vehicles alongside
VehicleInputSyncCoreandNetworkObject. Propagates vehicle throttle, steering, and handbrake inputs across the network usingSyncVarfields updated via owner[ServerRpc].
3. Global & Scene Services
FishNetProviderSO: ScriptableObject strategy extending
NetworkProviderSO. Resolves globalInstanceFinder.NetworkManager, instantiatesFishNetTransport, registers custom payload serializers, and sets up the pedestrian broadcaster.FishNetPlayerSpawnerSO: ScriptableObject extending
NetworkPlayerSpawnerSO. Executes server-side player instantiation via FishNet’sServerManager.Spawn()with assigned connection ownership.FishNetTransport: Low-level transport bridge implementing
INetworkTransport. Maps connection state events and routes broadcasts viaBroadcastInvoker<T>.FishNetMessageRegistry: Central binder connecting data payloads to FishNet
IBroadcastwrappers insideUniversalNetworkService.FishNetIdentityWrapper & FishNetBehaviourWrapper: Framework wrappers implementing
INetworkIdentityandINetworkBehaviourover FishNet’sNetworkObject.FishNetVehicleNetworkSync: Inherits from
MonoVehicleNetworkSyncBase. Manages server-side driver assignment, physics toggles, and network ownership delegation (usingGiveOwnershipor spawning unspawned network objects) when players enter or exit vehicles.
Data Payloads & Custom Serialization
Custom Serializers:
VehicleSnapshotSerializers: Provides custom extension methods for FishNetWriterandReaderto efficiently serialize individualVehicleSnapshotstructures and zero-allocationArraySegment<VehicleSnapshot>buffers.PedestrianSerializers: Serializes pedestrian lifecycle broadcasts (initial states, requests, transforms, animations, and ragdoll sync).
Broadcast Wrappers: Structs implementing
IBroadcast(e.g.,FishNetTrafficLightBroadcast,VehicleSpawnDataWrapper,VehicleDespawnDataWrapper,PedestrianSpawnBroadcastWrapper).