Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.

Commit aa41a2e

Browse files
committed
Remove admonition box in 1.9
1 parent c928bfc commit aa41a2e

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

versioned_docs/version-1.9.1/advanced-topics/client-anticipation.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ title: Client anticipation
55

66
import ImageSwitcher from '@site/src/ImageSwitcher.js';
77

8-
:::info Client-server only
9-
10-
Client anticipation is only relevant for games using a [client-server topology](../terms-concepts/client-server.md).
11-
12-
:::
138
Netcode for GameObjects doesn't support full client-side prediction and reconciliation, but it does support client anticipation: a simplified model that lacks the full rollback-and-replay prediction loop, but still provides a mechanism for anticipating the server result of an action and then correcting if you anticipated incorrectly.
149

1510
Client anticipation uses `AnticipatedNetworkVariable<T>` and `AnticipatedNetworkTransform`. By calling their various `Anticipate` methods, you can set a visual value that differs from the server value and then react to updates from the server in different ways depending on how you have configured the `StaleDataHandling` property. Additionally, both include a [`Smooth` method](#smoothing-for-corrections) to support interpolation, either when receiving updated values from the server that don't match the anticipated value, or when receiving updates from other clients' actions that weren't anticipated at all.
@@ -19,15 +14,15 @@ Client anticipation uses `AnticipatedNetworkVariable<T>` and `AnticipatedNetwork
1914
Games with a server-authoritative architecture often face the problem of making the game feel responsive despite [latency](../learn/ladandpacketloss.md). For example, when a user wants to change the color of an object from green to blue they click a button in the UI, an RPC is sent to the server, and the server changes the object to blue. From the client's perspective, the object doesn't change to blue until the server responds to that message, resulting in a perceived delay for the user.
2015

2116
<figure>
22-
<ImageSwitcher
17+
<ImageSwitcher
2318
lightImageSrc="/sequence_diagrams/Anticipation/ServerAuthoritative.png?text=LightMode"
2419
darkImageSrc="/sequence_diagrams/Anticipation/ServerAuthoritative_Dark.png?text=DarkMode"/>
2520
</figure>
2621

2722
Client anticipation solves this problem by allowing a separation between the visual value and the authoritative value of an object. In this example, with anticipation, when the button is pressed to change the color from green to blue, the client *anticipates* the result of the command by visually changing the object to green while it waits for an update from the server:
2823

2924
<figure>
30-
<ImageSwitcher
25+
<ImageSwitcher
3126
lightImageSrc="/sequence_diagrams/Anticipation/ClientAnticipation.png?text=LightMode"
3227
darkImageSrc="/sequence_diagrams/Anticipation/ClientAnticipation_Dark.png?text=DarkMode"/>
3328
</figure>
@@ -48,15 +43,15 @@ Anticipation systems need to be able to handle stale data. Stale data refers to
4843
Expanding the example above to include a second client that's also trying to change the color of the same object highlights this problem. If client A tries to change the object to blue, and then client B tries to change it to red, client A sees a delayed switch to blue, followed by a switch to red (which is fine because this is actually what happened). Client B, however, clicks the button to change it to red, then sees it change to blue, followed by a change to red.
4944

5045
<figure>
51-
<ImageSwitcher
46+
<ImageSwitcher
5247
lightImageSrc="/sequence_diagrams/Anticipation/ServerAuthoritativeMultiClient.png?text=LightMode"
5348
darkImageSrc="/sequence_diagrams/Anticipation/ServerAuthoritativeMultiClient_Dark.png?text=DarkMode"/>
5449
</figure>
5550

5651
With client anticipation, this scenario plays out differently: client A anticipates the change to blue, so it happens immediately, and then later sees the object change to red (which, again, is fine). Client B also sees the object change to red immediately, but because a change to blue is already in progress, that overwrites client B's anticipated value, causing it to flicker briefly to blue from client A's request before changing back to red again from client B's request.
5752

5853
<figure>
59-
<ImageSwitcher
54+
<ImageSwitcher
6055
lightImageSrc="/sequence_diagrams/Anticipation/StaleDataNoPolicy.png?text=LightMode"
6156
darkImageSrc="/sequence_diagrams/Anticipation/StaleDataNoPolicy_Dark.png?text=DarkMode"/>
6257
</figure>
@@ -72,7 +67,7 @@ There are two ways you can respond to stale data, which are determined by the `S
7267
If `StaleDataHandling` is set to `StaleDataHandling.Ignore`, stale data doesn't roll back the value of the variable or transform to the server value and doesn't trigger the [`OnReanticipate` event](#onreanticipate-event). `ShouldReanticipate` remains false in the event something else triggers the callback. The authoritative value is still updated, however, and for `AnticipatedNetworkVariable`, the `OnAuthoritativeValueUpdated` callback is still called. The result for our example is that, for client B, the change to blue is recognized as being sequenced before its change to red, and is thus ignored, eliminating the flickering. This is the default behavior for `AnticipatedNetworkVariable<T>`.
7368

7469
<figure>
75-
<ImageSwitcher
70+
<ImageSwitcher
7671
lightImageSrc="/sequence_diagrams/Anticipation/StaleDataIgnore.png?text=LightMode"
7772
darkImageSrc="/sequence_diagrams/Anticipation/StaleDataIgnore_Dark.png?text=DarkMode"/>
7873
</figure>
@@ -81,7 +76,7 @@ darkImageSrc="/sequence_diagrams/Anticipation/StaleDataIgnore_Dark.png?text=Dark
8176
If `StaleDataHandling` is set to `StaleDataHandling.Reanticipate`, stale data is treated the same way as any other server data updates. The value is rolled back, `ShouldReanticipate` is set to true, and the [`OnReanticipate` event](#onreanticipate-event) fires. In typical client prediction systems, this generally involves replaying the player's input from the time of the incoming data to now, which results in re-performing the switch to red.
8277

8378
<figure>
84-
<ImageSwitcher
79+
<ImageSwitcher
8580
lightImageSrc="/sequence_diagrams/Anticipation/StaleDataReanticipate.png?text=LightMode"
8681
darkImageSrc="/sequence_diagrams/Anticipation/StaleDataReanticipate_Dark.png?text=DarkMode"/>
8782
</figure>

0 commit comments

Comments
 (0)