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.
Implements
Inherited Members
Namespace: Unity.NetCode
Assembly: Unity.NetCode.dll
Syntax
[Serializable]
public struct NetworkTick : IEquatable<NetworkTick>
Constructors
NetworkTick(uint)
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 |
---|---|---|
uint | 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 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 bool IsValid { get; }
Property Value
Type | Description |
---|---|
bool |
SerializedData
The serialized data for a tick. Includes both validity and tick index.
Declaration
public uint SerializedData { get; set; }
Property Value
Type | Description |
---|---|
uint |
TickIndexForValidTick
Get the tick index assuming the tick is valid. Should be used with care since ticks will wrap around.
Declaration
public uint TickIndexForValidTick { get; }
Property Value
Type | Description |
---|---|
uint |
TickValue
Helper property to enable exception-free visibility in the Entity Inspector
Declaration
[CreateProperty]
public FixedString32Bytes TickValue { get; }
Property Value
Type | Description |
---|---|
FixedString32Bytes |
Methods
Add(uint)
Add a delta to the tick, assumes the tick is valid.
Declaration
public void Add(uint delta)
Parameters
Type | Name | Description |
---|---|---|
uint | 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 |
---|---|
bool |
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 |
---|---|
bool |
GetHashCode()
Get a hash for the tick.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int |
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 |
---|---|
bool |
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(uint)
Subtract a delta from the tick, assumes the tick is valid.
Declaration
public void Subtract(uint delta)
Parameters
Type | Name | Description |
---|---|---|
uint | 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 |
---|---|
int |
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
operator ==(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 |
---|---|
bool |
operator !=(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 |
---|---|
bool |