FishNet Documentation

repository·main·Indexed 21 days ago

https://github.com/firstgeargames/fishnet

A feature-rich Unity networking solution version 4.7.2 designed for reliability, efficiency, and flexibility. It supports various game genres including MMOs, shooters, and physics-based games. The library includes tools for NetworkTransform benchmarking, collider rollback, HashGrid implementation, character controller prediction, additive scene management, and a fast object pooling system.

Tokens
1.9K
Snippets
3
Records
15
Agent score
84%

What's inside FishNet

  1. What is Cecil and how can it be used

    main

    Cecil (Mono.Cecil) is a library used to generate and inspect programs and libraries in the ECMA CIL (Common Intermediate Language) form. It provides a powerful object model for interacting with .NET binaries without the overhead of loading assemblies via standard Reflection.

    Key capabilities include:

    • Analyzing .NET binaries: Inspecting assemblies, types, and methods using a simple object model.
    • Modifying .NET binaries: Altering IL (Intermediate Language) code, adding new metadata structures, and modifying existing ones.
  2. Understand Collider Rollback Visual Indicators

    main

    When running the ColliderRollback demo, the following visual indicators are used to show the difference between server-side state and rolled-back state:

    • Red: Indicates the position where the object was rolled back to on the server.
    • Green: Indicates the actual position of the object on the server.

    Note: Rollback indicators in this demo will not display correctly when running in clientHost mode.

  3. How prediction and input synchronization work in the Character Controller demo

    main

    The Character Controller demo utilizes several specific networking patterns to ensure smooth movement and prediction:

    • Input Synchronization: The server and all clients run the same inputs. This is achieved by enabling State Forwarding on the NetworkObject inspector.
    • Platform Attachment: A NetworkTrigger is used to attach characters to platforms. In the prefab hierarchy, the trigger is attached as a child of the NetworkObject (rather than the graphical object) to ensure it is not modified by smoothing logic that occurs outside the tick system.
    • Moving Platform Prediction: Moving platforms predict fully into the future, allowing clients to step on them in real-time.

    Note on Spectating: Spectated objects may appear to correct (jitter/snap) when moving onto a moving platform. To fix this, you must balance the amount of future prediction between the platform and the spectated objects.

  4. Configure NetworkTransform Benchmark settings

    main

    You can customize the benchmark behavior by modifying specific objects within the NetworkTransform Benchmark scene:

    • Spawned Object Configuration: Select any prefab named NetworkTransform Benchmark XYZ to adjust its properties.
    • Spawn Count: Select the Prefab Spawner object in the scene and modify the amount field.
    • Tick Rate: Select the NetworkManager object and adjust the Tick Rate setting located on the TimeManager component.
    • Object Movement and Rates: Open the NetworkTransform Benchmark XYZ prefab and configure the MoveRandomly component to change how objects move and at what rate.
  5. Run the ColliderRollback Demo

    main

    The ColliderRollback demo demonstrates how to use collider rollback for raycasts. This demo requires Fish-Networking Pro.

    To run the demo, you must simulate a networked environment by running two separate instances of the project:

    1. Start two separate Unity editors or two separate builds.
    2. Press Play on both instances.
    3. Configure one instance to run as the Server and the other to run as the Client.
  6. Set up and run the HashGrid demo

    main

    To experience the HashGrid implementation, follow these steps:

    1. Open the demo scene as a server, clientHost, or client only.
    2. Press Play in the Unity Editor.

    Important Notes:

    • The demo is specifically configured to work on clientHost. For production environments, FishNet supports separate client and server architectures as well as clientHost.
    • You can use the Scene view to observe objects appearing and disappearing in real-time as the player object moves between different grid spots.
  7. Use Fast Object Pool to retrieve and store objects

    main

    The ObjectPool component provides methods for managing object lifecycles that mimic Unity's Instantiate and Destroy workflows.

    Retrieving Objects

    Use ObjectPool.Retrieve() to get an object from the pool. This method mimics Unity's Instantiate overrides. You can retrieve specific types (such as scripts) using the generic version:

    • ObjectPool.Retrieve()
    • ObjectPool.Retrieve<T>()

    Storing Objects

    Use ObjectPool.Store() to return an object to the pool. You can also specify a delay when storing an object, similar to how Destroy(obj, delay) works in Unity.

  8. Set up Fast Object Pool

    main

    To use the Fast Object Pool, you must first ensure the Fundamentals package is installed in your project.

    To set up a pool in your scene:

    1. Add the ObjectPool component to any object in your scene.
    2. (Optional) To ensure the pool persists across scene changes, add the ObjectPool component to an object that is marked with DontDestroyOnLoad.
  9. Set up the Character Controller Prediction Demo

    main

    To use the Character Controller prediction demo, you must ensure that Beta ReplicateStates is enabled. This setting can be toggled via the Fish-Networking menu in the Unity editor.

    Setup Steps:

    1. Open the provided demo scene.
    2. Start the simulation as a Server, Host, or Client only.
    3. You can test using ParrelSync or by hosting the project locally.
  10. Implement additive scenes per connection

    main

    To implement a system where scenes are loaded additively based on the connection, you must manage scene loading on both the server and the client. The server should prewarm scenes to ensure they are ready, while clients hot-load and unload scenes as needed.

    Setup Requirements:

    1. Add all relevant scenes to the Unity Build Settings.
    2. Ensure the initial scene (AdditiveScene_Start) is at the top of the list, followed by the remainder of the additive scenes.
    3. Start the application on the AdditiveScene_Start scene for both server and client.

    Execution Flow:

    • Server: Start the server from the initial scene.
    • Client: Start the client from the initial scene.
    • ClientHost: The demo supports clientHost mode, as well as standalone server or client modes.

    Key Components:

    • ServerScenePrewarmer: Used on the server to load all scenes immediately upon startup. Scenes loaded this way are marked to not automatically unload and use KeepUnused when unloading.
    • ObserverManager: Located within the NetworkManager in the AdditiveScene_Start scene, this manages ObserverConditions to handle Area of Interest (AOI) based on scenes, objects within scenes, and relative distance to the player.