新增FishNet文档

This commit is contained in:
2026-09-20 15:53:11 +08:00
parent c403145db9
commit 179c282405
431 changed files with 15476 additions and 0 deletions
@@ -0,0 +1,17 @@
---
description: >-
Prediction components are for use with FishNet's prediction systems. Learn
more about each of them here!
---
# Prediction
There are a number of components specifically used for prediction. These include components specifically tied to the [Client-Side Prediction system](#user-content-fn-1)[^1] as well as ones that [are not](#user-content-fn-2)[^2]. Other components such as the NetworkObject can also have settings related to prediction, but they are not included in this subsection.
{% hint style="info" %}
Also consider viewing the [PredictionManager](../managers/predictionmanager.md) to customize global prediction settings.
{% endhint %}
[^1]: For example the NetworkColliders
[^2]: For example the Predicted Spawn and Predicted Owner
@@ -0,0 +1,17 @@
---
description: >-
The NetworkCollider components are a simple way to use Trigger and Collision
callbacks with prediction.
---
# Network Collider
Each component offers callbacks for OnEnter, OnStay, and OnExit, which work even during the prediction cycle. These components are needed because of a limitation in Unity's physics system that affects their OnCollisionEnter and OnCollisionExit methods, causing them to not always be executed.
{% hint style="success" %}
Fun fact: Fish-Networking is the only framework which provides a solution for using Enter/Exit collider callbacks with prediction!
{% endhint %}
{% hint style="warning" %}
Due to the complexity of physics with prediction we currently only support these components on primitive shapes: box, cube, sphere, circle, etc.
{% endhint %}
@@ -0,0 +1,29 @@
---
description: NetworkCollision is used to execute collision events for use with prediction.
---
# NetworkCollision
## Description
This component is used for receiving collision events for prediction enabled objects. It is very much equivalent to a Collider's `OnCollisionEnter`, `OnCollisionExit`, and `OnCollisionStay` messages, except that to receive these you would add this component to your game object and subscribe to its public events.
{% hint style="success" %}
Check out this API page [here](https://fish-networking.com/FishNet/api/api/FishNet.Component.Prediction.NetworkCollider.html) for the specific details.
{% endhint %}
## Settings
<div align="left"><figure><img src="../../../../.gitbook/assets/network-collision-component.png" alt=""><figcaption><p>Default settings</p></figcaption></figure></div>
### :gear: **Maximum Simultaneous Hits**
> This is the maximum number of simultaneous hits that the component will check for. You can use this field to customize how many overlapping colliders the component should be able to detect. It should be noted that having too large of a value will decrease its performance. In most cases, the default value of 16 suffices.
### :gear: **Additional Size**
> The **Additional Size** determines the distance in units by which collision traces are extended. This extension helps prevent missed overlaps when colliders do not intersect sufficiently. Depending on the scale used in your game you may want to raise or lower this value.
### :gear: **Layers**
> These are the Layers to detect collisions on. This is used when value is not set as **Nothing**.
@@ -0,0 +1,35 @@
---
description: >-
NetworkCollision2D is used to execute collision2D events for use with
prediction.
---
# NetworkCollision2D
## Description
This component is used for receiving collision events for prediction enabled objects for 2D Colliders. It is very much equivalent to a Collider's `OnCollisionEnter`, `OnCollisionExit`, and `OnCollisionStay` messages, except that to receive these you would add this component to your game object and subscribe to its public events.
{% hint style="success" %}
Check out this API page [here](https://fish-networking.com/FishNet/api/api/FishNet.Component.Prediction.NetworkCollider2D.html) for the specific details.
{% endhint %}
## Settings
<div align="left"><figure><img src="../../../../.gitbook/assets/network-collision-2d-component.png" alt=""><figcaption><p>Default settings</p></figcaption></figure></div>
### :gear: **Maximum Simultaneous Hits**
> This is the maximum number of simultaneous hits that the component will check for. You can use this field to customize how many overlapping colliders the component should be able to detect. It should be noted that having too large of a value will decrease its performance. In most cases, the default value of 16 suffices.
### :gear: **History Duration**
> This determines how long collision history is retained. Lower values optimize memory usage slightly, but may lead to the collision records becoming out of sync on clients with excessively high latency.
### :gear: **Additional Size**
> The **Additional Size** determines the distance in units by which collision traces are extended. This extension helps prevent missed overlaps when colliders do not intersect sufficiently. Depending on the scale used in your game you may want to raise or lower this value.
### :gear: **Layers**
> These are the Layers to detect collisions on. This is used when value is not set as **Nothing**.
@@ -0,0 +1,29 @@
---
description: NetworkTrigger is used to execute trigger events for use with prediction.
---
# NetworkTrigger
## Description
This component is used for receiving trigger events for prediction enabled objects for 2D Colliders. It is very much equivalent to a Collider's `OnTriggerEnter`, `OnTriggerExit`, and `OnTriggerStay` messages, except that to receive these you would add this component to your game object and subscribe to its public events.
{% hint style="success" %}
Check out this API page [here](https://fish-networking.com/FishNet/api/api/FishNet.Component.Prediction.NetworkCollider.html) for the specific details.
{% endhint %}
## Settings
<div align="left"><figure><img src="../../../../.gitbook/assets/network-trigger-component.png" alt=""><figcaption><p>Default settings</p></figcaption></figure></div>
### :gear: **Maximum Simultaneous Hits**
> This is the maximum number of simultaneous hits that the component will check for. You can use this field to customize how many overlapping colliders the component should be able to detect. It should be noted that having too large of a value will decrease its performance. In most cases, the default value of 16 suffices.
### :gear: **Additional Size**
> The **Additional Size** determines the distance in units by which collision traces are extended. This extension helps prevent missed overlaps when colliders do not intersect sufficiently. Depending on the scale used in your game you may want to raise or lower this value.
### :gear: **Layers**
> These are the Layers to detect collisions on. This is used when value is not set as **Nothing**.
@@ -0,0 +1,33 @@
---
description: NetworkTrigger2D is used to execute trigger2D events for use with prediction.
---
# NetworkTrigger2D
## Description
This component is used for receiving trigger events for prediction enabled objects for 2D Colliders. It is very much equivalent to a Collider's `OnTriggerEnter`, `OnTriggerExit`, and `OnTriggerStay` messages, except that to receive these you would add this component to your game object and subscribe to its public events.
{% hint style="success" %}
Check out this API page [here](https://fish-networking.com/FishNet/api/api/FishNet.Component.Prediction.NetworkCollider2D.html) for the specific details.
{% endhint %}
## Settings
<div align="left"><figure><img src="../../../../.gitbook/assets/network-trigger-2d-component.png" alt=""><figcaption><p>Default settings</p></figcaption></figure></div>
### :gear: **Maximum Simultaneous Hits**
> This is the maximum number of simultaneous hits that the component will check for. You can use this field to customize how many overlapping colliders the component should be able to detect. It should be noted that having too large of a value will decrease its performance. In most cases, the default value of 16 suffices.
### :gear: **History Duration**
> This determines how long collision history is retained. Lower values optimize memory usage slightly, but may lead to the collision records becoming out of sync on clients with excessively high latency.
### :gear: **Additional Size**
> The **Additional Size** determines the distance in units by which collision traces are extended. This extension helps prevent missed overlaps when colliders do not intersect sufficiently. Depending on the scale used in your game you may want to raise or lower this value.
### :gear: **Layers**
> These are the Layers to detect collisions on. This is used when value is not set as **Nothing**.
@@ -0,0 +1,27 @@
---
description: >-
This component can be used to prevent client side objects from running physics
too quickly due to prediction replays.
---
# OfflineRigidbody
## Description
When using predictions, especially physics prediction, the client will often re-simulate physics to make corrections. You generally want to add an OfflineRigidbody component to prevent non-networked objects from simulating multiple times during a correction.
## Settings
<div align="left"><figure><img src="../../../.gitbook/assets/offline-rigidbody-component.png" alt=""><figcaption><p>Default settings</p></figcaption></figure></div>
### :gear: **Rigidbody Type**
> This is to specify if the offline object uses a rigidbody3d, or 2d.
### :gear: **Get In Children**
> This setting should be enabled if you have child rigidbodies. Keeping this disabled when child rigidbodies are not present will save a very small amount of performance.
## Combining Smoothers
There is a fair chance you will want to have the graphical object on your rigidbodies smoothed between ticks. There are a variety of components to accomplish this; see them on the [tick-smoothers](../tick-smoothers/ "mention") page.
@@ -0,0 +1,26 @@
---
description: >-
The PredictedOwner component allows a user to claim ownership of an object
immediately and be able to use it before the server officially gives the
ownership over.
---
# PredictedOwner
## Description
The **PredictedOwner** allows clients to immediately simulate ownership on an object without waiting for the server's response. This overcomes delays from client latency, allowing for a seamless transition of ownership. Placing this component on an object enables this feature for that network object.
A client can use the [`TakeOwnership`](https://fish-networking.com/FishNet/api/api/FishNet.Component.Ownership.PredictedOwner.html#FishNet_Component_Ownership_PredictedOwner_TakeOwnership_System_Boolean_) method to anticipatorily claim ownership of an object. You can also access the [`PreviousOwner`](https://fish-networking.com/FishNet/api/api/FishNet.Component.Ownership.PredictedOwner.html#FishNet_Component_Ownership_PredictedOwner_PreviousOwner) of the object and by inheriting from this component you can add checks to the server to decide whether to accept the ownership change or reject it. This can be done by overriding the [`OnTakeOwnership`](https://fish-networking.com/FishNet/api/api/FishNet.Component.Ownership.PredictedOwner.html#FishNet_Component_Ownership_PredictedOwner_OnTakeOwnership_FishNet_Connection_NetworkConnection_System_Boolean_) method and not handing over the ownership for whatever reason you may have.
{% hint style="success" %}
Check out its full API page for more specific methods and properties [here](https://fish-networking.com/FishNet/api/api/FishNet.Component.Ownership.PredictedOwner.html).
{% endhint %}
## Settings
<div align="left"><figure><img src="../../../.gitbook/assets/predicted-owner-component.png" alt=""><figcaption><p>Default settings</p></figcaption></figure></div>
### :gear: **Allow Take Ownership**
> This enables or disables the functionality of this component, and can be set at run-time from the server with this method: [`SetAllowTakeOwnership`](https://fish-networking.com/FishNet/api/api/FishNet.Component.Ownership.PredictedOwner.html#FishNet_Component_Ownership_PredictedOwner_SetAllowTakeOwnership_System_Boolean_).
@@ -0,0 +1,35 @@
---
description: >-
The PredictedSpawn component allows you to spawn this Network Object directly
on the client side.
---
# PredictedSpawn
## Description
Adding this component to a [NetworkObject](../../../guides/features/networked-gameobjects-and-scripts/networkobjects/) will allow you to adjust [predicted spawning](../../../guides/features/networked-gameobjects-and-scripts/spawning/predicted-spawning.md) settings for the object. To enable this feature you must also enable predicted spawning within the [ServerManager](../managers/server-manager.md).
The **PredictedSpawn** component allows you to inherit from it and then override any of several available virtual methods to customize and validate predicted spawns.
{% hint style="success" %}
Check out its full API page for the specific methods [here](https://fish-networking.com/FishNet/api/api/FishNet.Component.Ownership.PredictedSpawn.html).
{% endhint %}
## Settings
<div align="left"><figure><img src="../../../.gitbook/assets/predicted-spawn-component.png" alt=""><figcaption><p>Default settings</p></figcaption></figure></div>
### :gear: **Allow Spawning**
> This allows clients to predicted spawn this object. You can change this at run-time with the [`SetAllowSpawning`](https://fish-networking.com/FishNet/api/api/FishNet.Component.Ownership.PredictedSpawn.html#FishNet_Component_Ownership_PredictedSpawn_SetAllowDespawning_System_Boolean_) method. Just be sure to do so on the client and server side.
### :gear: **Allow Despawning**
> This allows clients to predicted despawn this object. You can change this at run-time with the [`SetAllowDespawning`](https://fish-networking.com/FishNet/api/api/FishNet.Component.Ownership.PredictedSpawn.html#FishNet_Component_Ownership_PredictedSpawn_SetAllowDespawning_System_Boolean_) method. Just be sure to do so on the client and server side.
{% hint style="info" %}
You can implement WritePayload and ReadPayload in your classes which inherit NetworkBehaviour to send data with spawn messages. This can even be used for predicted spawns to the server, and clients!
Learn more about that here: [spawn-payloads.md](../../../guides/features/networked-gameobjects-and-scripts/spawning/spawn-payloads.md "mention")
{% endhint %}