Struct NetworkTick
A simple struct used to represent a network tick. This is using a uint internally, but it has special logic to deal with invalid ticks, and it handles wrap around correctly.
Inherited Members
Namespace: Unity.NetCode
Syntax
[Serializable]
public struct NetworkTick : IEquatable<NetworkTick>
Constructors
NetworkTick(UInt32)
Constructor, the start tick can be 0. Use this instead of the default constructor since that will generate an invalid tick.
Declaration
public NetworkTick(uint start)
Parameters
| Type | Name | Description |
|---|---|---|
| UInt32 | start | The tick index to initialize the NetworkTick with. |
Properties
Invalid
A value representing an invalid tick, this is the same as 'default' but provide more context in the code.
Declaration
public static readonly NetworkTick Invalid { get; }
Property Value
| Type | Description |
|---|---|
| NetworkTick |
IsValid
Check if the tick is valid. Not all operations will work on invalid ticks.
Declaration
public readonly bool IsValid { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
SerializedData
The serialized data for a tick. Includes both validity and tick index.
Declaration
public uint SerializedData { get; set; }
Property Value
| Type | Description |
|---|---|
| UInt32 |
TickIndexForValidTick
Get the tick index assuming the tick is valid. Should be used with care since ticks will wrap around.
Declaration
public readonly uint TickIndexForValidTick { get; }
Property Value
| Type | Description |
|---|---|
| UInt32 |
TickValue
Helper property to enable exception-free visibility in the Entity Inspector
Declaration
[CreateProperty]
public readonly FixedString32Bytes TickValue { get; }
Property Value
| Type | Description |
|---|---|
| FixedString32Bytes |
Methods
Add(UInt32)
Add a delta to the tick, assumes the tick is valid.
Declaration
public void Add(uint delta)
Parameters
| Type | Name | Description |
|---|---|---|
| UInt32 | delta | The value to add to the tick |
Decrement()
Decrement the tick, assumes the tick is valid.
Declaration
public void Decrement()
Equals(Object)
Compare two ticks, also works for invalid ticks.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | obj |
Returns
| Type | Description |
|---|---|
| Boolean |
Overrides
Equals(NetworkTick)
Compare two ticks, also works for invalid ticks.
Declaration
public bool Equals(NetworkTick compare)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkTick | compare |
Returns
| Type | Description |
|---|---|
| Boolean |
Implements
GetHashCode()
Get a hash for the tick.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| Int32 |
Overrides
Increment()
Increment the tick, assumes the tick is valid.
Declaration
public void Increment()
IsNewerThan(NetworkTick)
Check if this tick is newer than another tick. Assumes both ticks are valid.
Declaration
public bool IsNewerThan(NetworkTick old)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkTick | old | The tick to compare with |
Returns
| Type | Description |
|---|---|
| Boolean |
Remarks
The ticks wraps around, so if either tick is stored for too long (several days assuming 60hz) the result might not be correct.
Subtract(UInt32)
Subtract a delta from the tick, assumes the tick is valid.
Declaration
public void Subtract(uint delta)
Parameters
| Type | Name | Description |
|---|---|---|
| UInt32 | delta | The value to subtract from the tick |
TicksSince(NetworkTick)
Compute the number of ticks which passed since an older tick. Assumes both ticks are valid. If the passed in tick is newer this will return a negative value.
Declaration
public int TicksSince(NetworkTick older)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkTick | older | The tick to compute passed ticks from |
Returns
| Type | Description |
|---|---|
| Int32 |
ToFixedString()
Convert the tick to a fixed string. Also handles invalid ticks.
Declaration
public FixedString32Bytes ToFixedString()
Returns
| Type | Description |
|---|---|
| FixedString32Bytes | The tick index as a fixed string, or "Invalid" for invalid ticks. |
Operators
Equality(in NetworkTick, in NetworkTick)
Compare two ticks, also works for invalid ticks.
Declaration
public static bool operator ==(in NetworkTick a, in NetworkTick b)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkTick | a | |
| NetworkTick | b |
Returns
| Type | Description |
|---|---|
| Boolean |
Inequality(in NetworkTick, in NetworkTick)
Compare two ticks, also works for invalid ticks.
Declaration
public static bool operator !=(in NetworkTick a, in NetworkTick b)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkTick | a | |
| NetworkTick | b |
Returns
| Type | Description |
|---|---|
| Boolean |