> For the complete documentation index, see [llms.txt](https://kinematicsoup.gitbook.io/reactor/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinematicsoup.gitbook.io/reactor/api-reference/ks.reactor.client/ks.reactor.client.kstimekeeper.md).

# Class ksTimeKeeper

Namespace: [KS.Reactor.Client](/reactor/api-reference/ks.reactor.client.md)\
Assembly: KSUnity.dll

Smoothly adjusts client time deltas to keep in sync with the server. Controls time values that determine how far predictors should interpolate/extrapolate the server frame data.

```csharp
public class ksTimeKeeper : ksITimeAdjuster
```

#### Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) ← [ksTimeKeeper](/reactor/api-reference/ks.reactor.client/ks.reactor.client.kstimekeeper.md)

#### Implements

[ksITimeAdjuster](/reactor/api-reference/ks.reactor.client/ks.reactor.client.ksitimeadjuster.md)

#### Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object\)), [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object-system-object\)), [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode), [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype), [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone), [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals), [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Properties

### Drift <a href="#ks_reactor_client_kstimekeeper_drift" id="ks_reactor_client_kstimekeeper_drift"></a>

How far ahead or behind in seconds we've drifted from the target latency. Each server frame received decreases this number.

```csharp
public float Drift { get; }
```

#### Property Value

[float](https://learn.microsoft.com/dotnet/api/system.single)

### DriftThreshold <a href="#ks_reactor_client_kstimekeeper_driftthreshold" id="ks_reactor_client_kstimekeeper_driftthreshold"></a>

Drift theshold in seconds to try keep the drift within. Smaller values will trigger time adjustments more frequently.

```csharp
public float DriftThreshold { get; set; }
```

#### Property Value

[float](https://learn.microsoft.com/dotnet/api/system.single)

### Extrapolating <a href="#ks_reactor_client_kstimekeeper_extrapolating" id="ks_reactor_client_kstimekeeper_extrapolating"></a>

Are we extrapolating passed the last frame?

```csharp
public bool Extrapolating { get; }
```

#### Property Value

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### FrameNum <a href="#ks_reactor_client_kstimekeeper_framenum" id="ks_reactor_client_kstimekeeper_framenum"></a>

Frame number for the server frame we are currently interpolating towards. ulong.MaxValue if we are extrapolating.

```csharp
public ulong FrameNum { get; }
```

#### Property Value

[ulong](https://learn.microsoft.com/dotnet/api/system.uint64)

### LastFrameNum <a href="#ks_reactor_client_kstimekeeper_lastframenum" id="ks_reactor_client_kstimekeeper_lastframenum"></a>

Frame number for the server frame we were interpolating towards last update. ulong.MaxValue if we were extrapolating.

```csharp
public ulong LastFrameNum { get; }
```

#### Property Value

[ulong](https://learn.microsoft.com/dotnet/api/system.uint64)

### LastTimeOffset <a href="#ks_reactor_client_kstimekeeper_lasttimeoffset" id="ks_reactor_client_kstimekeeper_lasttimeoffset"></a>

How long in seconds we were extrapolating or interpolating last update.

```csharp
public float LastTimeOffset { get; }
```

#### Property Value

[float](https://learn.microsoft.com/dotnet/api/system.single)

### MaxDrift <a href="#ks_reactor_client_kstimekeeper_maxdrift" id="ks_reactor_client_kstimekeeper_maxdrift"></a>

Max drift ahead or behind the server in seconds before applying a near-instant time correction. The adjustment still takes multiple frames so if more server frames arrive before we finish the adjustment, we increase the time correction and time adjustment duration to include them rather than doing multiple instant adjustments.

```csharp
public float MaxDrift { get; set; }
```

#### Property Value

[float](https://learn.microsoft.com/dotnet/api/system.single)

### MinAdjustmentDuration <a href="#ks_reactor_client_kstimekeeper_minadjustmentduration" id="ks_reactor_client_kstimekeeper_minadjustmentduration"></a>

Minimum duration of time adjustment in seconds. Time adjustments are applied over multiple frames to make the adjustment smooth. The adjustment duration is the larger of this amount or twice the time being corrected, unless the time correction exceeds max drift, in which case we do a near-instant time adjustment.

```csharp
public float MinAdjustmentDuration { get; set; }
```

#### Property Value

[float](https://learn.microsoft.com/dotnet/api/system.single)

### NumDriftExceeds <a href="#ks_reactor_client_kstimekeeper_numdriftexceeds" id="ks_reactor_client_kstimekeeper_numdriftexceeds"></a>

Number of consecuitive drift samples exceeding the threshold needed to trigger time correction.

```csharp
public int NumDriftExceeds { get; set; }
```

#### Property Value

[int](https://learn.microsoft.com/dotnet/api/system.int32)

### Restrainer <a href="#ks_reactor_client_kstimekeeper_restrainer" id="ks_reactor_client_kstimekeeper_restrainer"></a>

Time restrainer that slows down and eventually stops time when we go too long without receiving any server updates. Can be set to null to disable this behaviour.

```csharp
public ksTimeRestrainer Restrainer { get; set; }
```

#### Property Value

[ksTimeRestrainer](/reactor/api-reference/ks.reactor.client/ks.reactor.client.kstimerestrainer.md)

### TargetLatency <a href="#ks_reactor_client_kstimekeeper_targetlatency" id="ks_reactor_client_kstimekeeper_targetlatency"></a>

How far behind each server frame we try to be when that server frame arrives. Increasing reduces the likelyhood of getting ahead of the latest server frame, which increases client simulation accuracy as we won't have to extrapolate object transforms as often, but it also increases latency. By default this is set to zero to favour the lowest latency possible.

```csharp
public float TargetLatency { get; set; }
```

#### Property Value

[float](https://learn.microsoft.com/dotnet/api/system.single)

### TimeCorrection <a href="#ks_reactor_client_kstimekeeper_timecorrection" id="ks_reactor_client_kstimekeeper_timecorrection"></a>

Amount in seconds time is being corrected by.

```csharp
public float TimeCorrection { get; }
```

#### Property Value

[float](https://learn.microsoft.com/dotnet/api/system.single)

### TimeOffset <a href="#ks_reactor_client_kstimekeeper_timeoffset" id="ks_reactor_client_kstimekeeper_timeoffset"></a>

How long in seconds we are extrapolating or interpolating in the current frame.

```csharp
public float TimeOffset { get; }
```

#### Property Value

[float](https://learn.microsoft.com/dotnet/api/system.single)

## Methods

### Initialize() <a href="#ks_reactor_client_kstimekeeper_initialize" id="ks_reactor_client_kstimekeeper_initialize"></a>

Resets/clears timing data.

```csharp
public void Initialize()
```

### OnClientUpdate(float) <a href="#ks_reactor_client_kstimekeeper_onclientupdate_system_single" id="ks_reactor_client_kstimekeeper_onclientupdate_system_single"></a>

Called once per frame to adjust deltaTime to stay in sync with the server. Advances time offset and frame num for predictor interpolation/extrapolation.

```csharp
public float OnClientUpdate(float deltaTime)
```

#### Parameters

`deltaTime` [float](https://learn.microsoft.com/dotnet/api/system.single)

Unscaled time delta in seconds of simulation time since the last frame.

#### Returns

[float](https://learn.microsoft.com/dotnet/api/system.single)

adjusted delta time in seconds.

### OnServerUpdate(float, ulong) <a href="#ks_reactor_client_kstimekeeper_onserverupdate_system_single_system_uint64" id="ks_reactor_client_kstimekeeper_onserverupdate_system_single_system_uint64"></a>

Called once per server update. Updates drift and checks if we need to initiate a time correction.

```csharp
public void OnServerUpdate(float unscaledDeltaTime, ulong frameNum)
```

#### Parameters

`unscaledDeltaTime` [float](https://learn.microsoft.com/dotnet/api/system.single)

Time delta in seconds of server simulation time (unscaled) since the last update.

`frameNum` [ulong](https://learn.microsoft.com/dotnet/api/system.uint64)

Frame number from the server.
