SetNet.StateSync.Prediction
1.1.0
dotnet add package SetNet.StateSync.Prediction --version 1.1.0
NuGet\Install-Package SetNet.StateSync.Prediction -Version 1.1.0
<PackageReference Include="SetNet.StateSync.Prediction" Version="1.1.0" />
<PackageVersion Include="SetNet.StateSync.Prediction" Version="1.1.0" />
<PackageReference Include="SetNet.StateSync.Prediction" />
paket add SetNet.StateSync.Prediction --version 1.1.0
#r "nuget: SetNet.StateSync.Prediction, 1.1.0"
#:package SetNet.StateSync.Prediction@1.1.0
#addin nuget:?package=SetNet.StateSync.Prediction&version=1.1.0
#tool nuget:?package=SetNet.StateSync.Prediction&version=1.1.0
<p align="center"> <img src="https://raw.githubusercontent.com/Povstalez/SetNet/master/assets/icon.png" alt="SetNet" width="96"> </p>
SetNet.StateSync.Prediction
Client-side prediction & reconciliation for SetNet.StateSync.
On a server-authoritative game the client can't wait for the server to confirm every move — that round-trip would make the local player feel laggy. The fix is prediction: apply the input locally right now, but keep it around until the server acknowledges it. When the authoritative snapshot arrives, snap the owned entity to the server's state and replay the inputs the server hasn't processed yet on top of it (rewind & replay). The player stays responsive and the world stays server-authoritative.
PredictionBuffer<TInput> is the bookkeeping for that loop: record each input against the sequence number ClientReplication.SendInput stamps on it, then Reconcile against the sequence the server echoes back (ClientReplication.LastProcessedInput).
Install
dotnet add package SetNet
dotnet add package SetNet.StateSync
dotnet add package SetNet.StateSync.Prediction
Usage
using SetNet.StateSync;
using SetNet.StateSync.Prediction;
var replication = client.UseStateSync(new StateSyncOptions { InterpolationDelayMs = 100 });
var buffer = new PredictionBuffer<MyInput>();
// --- each input frame: predict locally, then send + record ---
MyInput input = ReadInput();
Apply(input); // move the owned entity NOW (prediction)
uint seq = replication.SendInput(Serialize(input)); // send to server, get the sequence stamped on it
buffer.Record(seq, input); // remember it until the server acks
// --- each corrective snapshot: snap to authority, then replay unacked inputs ---
replication.Update();
var owned = replication.OwnedEntity; // NetworkEntityView? for the entity you own
if (owned != null)
{
SnapLocalEntityTo(owned.GetVec3(0)); // authoritative position (rewind)
buffer.Reconcile(replication.LastProcessedInput, Apply); // drop acked, replay the rest
}
Reconcile removes every input the server has already processed (seq ≤ lastProcessedInput) and re-applies the remaining ones in order through the apply callback — the same Apply you use for local prediction. After it returns, the owned entity is at the authoritative state advanced by all still-in-flight inputs.
API
| Member | Purpose |
|---|---|
new PredictionBuffer<TInput>(int maxPending = 256) |
Create the buffer; keeps at most maxPending unacknowledged inputs |
void Record(uint seq, TInput input) |
Record an input you just applied locally, tagged with the seq returned by SendInput |
void Reconcile(uint lastProcessedInput, Action<TInput> apply) |
Drop inputs with seq ≤ lastProcessedInput, replay the rest in order via apply |
int PendingCount |
Number of inputs awaiting server acknowledgement |
Notes
- Determinism is on you. Reconciliation only feels right if replaying the same input from the same state produces the same result. Keep your movement/simulation step deterministic and side-effect-free (no per-frame randomness, no reads of wall-clock time inside
apply). - Snap before you replay.
Reconcilereplays on top of current local state, so first snap the owned entity to the server's authoritative values (replication.OwnedEntity), then callReconcile. - Predict only what you own. Prediction is for the local player's entity (
OwnedEntity); everything else is smoothed by interpolation inSetNet.StateSync. Don't predict entities the server owns. - Buffer cap: if more than
maxPendinginputs pile up unacknowledged (e.g. a long stall), the oldest are dropped. The default 256 covers many seconds at typical input rates. - Pure bookkeeping — no network I/O of its own. It sits alongside the
ClientReplicationyou already drive each frame.
Documentation & source
- 🐙 https://github.com/Povstalez/SetNet — full module catalog in docs/MODULES.md
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- SetNet.StateSync (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.0 | 127 | 7/2/2026 |