Struct NetConditions
- Namespace
- Unity.Multiplayer.Core
Simulated latency, jitter and packet loss for the link between this peer and the others, applied by Unity Transport's simulator pipeline stage.
public struct NetConditions : IEquatable<NetConditions>
- Implements
- Inherited Members
Remarks
Every value describes this peer's own link: each packet it sends is delayed by LatencyMs (plus or minus up to JitterMs) and dropped with a chance of PacketLossPercent, and so is each packet it receives. A client on the Lossy profile therefore sees about 300 ms more round trip and loses about 5% of the packets each way. Set it on the clients to test what a player on a bad link sees, or on the server to put every player there; set on both ends, the effects add up.
Loss happens below Unity Transport's reliability, so reliable traffic (RPCs by default, synced fields, spawns, connection approval) still arrives, later; unreliable RPCs are really lost.
The simulator stage exists only where Netcode for GameObjects builds it: the editor and development
builds (unless UNITY_MP_TOOLS_NETSIM_DISABLED_IN_DEVELOP is defined) and release builds that define
UNITY_MP_TOOLS_NETSIM_ENABLED_IN_RELEASE. Elsewhere conditions are ignored, with a warning. Multiplayer
Tools' Network Simulator component drives the same stage, so use one or the other on a given peer.
Constructors
NetConditions(int, int, int)
Creates a set of conditions. Check it with Validate().
public NetConditions(int latencyMs, int jitterMs, int packetLossPercent)
Parameters
Fields
MaxLatencyMs
Longest accepted LatencyMs.
public const int MaxLatencyMs = 5000
Field Value
Properties
IsNone
True when nothing is simulated.
public bool IsNone { get; }
Property Value
IsValid
True when Validate() finds no problems.
public bool IsValid { get; }
Property Value
JitterMs
Up to this many milliseconds more or less than LatencyMs, at random per packet (0 to LatencyMs). Packets can arrive out of order; Unity Transport's sequenced pipelines put them back.
public readonly int JitterMs { get; }
Property Value
LatencyMs
Milliseconds added to every packet this peer sends and every one it receives (0 to MaxLatencyMs).
public readonly int LatencyMs { get; }
Property Value
None
No simulation.
public static NetConditions None { get; }
Property Value
PacketLossPercent
Percentage of packets dropped, in each direction (0 to 100).
public readonly int PacketLossPercent { get; }
Property Value
Methods
Equals(object)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
Equals(NetConditions)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(NetConditions other)
Parameters
otherNetConditionsAn object to compare with this object.
Returns
For(NetConditionsProfile)
The conditions a named profile stands for. Custom (which has no numbers of its own) and unknown values give None.
public static NetConditions For(NetConditionsProfile profile)
Parameters
profileNetConditionsProfile
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
ToString()
For example 150 ms ±10 ms, 5% loss, or no simulation.
public override string ToString()
Returns
TryParseProfile(string, out NetConditionsProfile)
Parses a profile name, ignoring case: none (or off), broadband, mobile4g (or
4g), mobile3g (or 3g), lossy or custom.
public static bool TryParseProfile(string text, out NetConditionsProfile profile)
Parameters
textstringprofileNetConditionsProfile
Returns
Validate()
Lists every problem with these numbers; an empty list means they are usable.
public IReadOnlyList<string> Validate()
Returns
Operators
operator ==(NetConditions, NetConditions)
Equality by value.
public static bool operator ==(NetConditions left, NetConditions right)
Parameters
leftNetConditionsrightNetConditions
Returns
operator !=(NetConditions, NetConditions)
Inequality by value.
public static bool operator !=(NetConditions left, NetConditions right)
Parameters
leftNetConditionsrightNetConditions