Nebula
Core

PredictedBehaviour<TInput>

A server-authoritative, client-predicted behaviour (the player controller, typically).

generated from the sources
public abstract class PredictedBehaviour<TInput> : PredictedBehaviourBase where TInput : struct, INetworkInput

A server-authoritative, client-predicted behaviour (the player controller, typically).

  • On the owning client, GatherInput runs every tick, the input is sent and Simulate is run immediately (prediction).
  • On the authoritative worker, Simulate runs with the input for that tick. When the entity crosses to another worker the buffered inputs travel with it, so the input stream never breaks.
  • The worker reports its post-simulation state to the owner; if the client's prediction for that tick disagrees by more than CorrectionThreshold, the client rewinds and replays.

Properties

LastInput

public TInput LastInput { get; }

The input consumed by the most recent Simulate call.

CorrectionThreshold

protected virtual float CorrectionThreshold { get; }

Positional error above which the client snaps to the server's state and replays.

IsReplaying

protected bool IsReplaying { get; }

True while Simulate is re-running already-predicted ticks after a server correction. One-shot side effects that are not part of the simulated state (tracers, sounds) should be skipped while this is set.

Methods

GatherInput

protected abstract TInput GatherInput();

Owning client only: sample the input for this tick.

GatherServerInput

protected virtual TInput GatherServerInput(uint tick);

Authoritative worker only, for entities with no owning client (NPCs): produce the input for this tick. The same Simulate then runs on it, so an NPC moves, shoots and hands over exactly like a player. Default: no input.

Simulate

protected abstract void Simulate(uint tick, in TInput input, float deltaTime);

Advance the entity by one tick. Must be a pure function of (current state, input): it runs on the server, on the predicting client, and again on the client during a replay.

WriteState

protected virtual void WriteState(NetworkWriter writer);

State the owner needs to reconcile. Default: position, rotation, velocity.

ReadState

protected virtual void ReadState(NetworkReader reader);

OnCorrected

protected virtual void OnCorrected(float magnitude);

Called on the client after a correction was applied (for effects/telemetry).

OnOriginShifted

public override void OnOriginShifted(Vector3 delta);

The prediction history holds frame positions; keep them valid across an origin shift. Call base when overriding.

NetworkTick

public sealed override void NetworkTick(uint tick, float deltaTime);

On this page