Struct GhostSendSystemData
Singleton entity that contains all the tweakable settings for the GhostSendSystem.
Implements
Inherited Members
Namespace: Unity.NetCode
Assembly: Unity.NetCode.dll
Syntax
[Serializable]
public struct GhostSendSystemData : IComponentData, IQueryTypeParameter
Fields
CleanupConnectionStatePerTick
The number of connections to cleanup unused serialization data for, in a single tick. Setting this higher can recover memory faster, but uses more CPU time.
Declaration
[Tooltip("The number of connections to cleanup unused serialization data for, in a single tick. Setting this higher can recover memory faster, but uses more CPU time.\n\nDefaults to 1.")]
[Min(1)]
public int CleanupConnectionStatePerTick
Field Value
Type | Description |
---|---|
int |
DefaultSnapshotPacketSize
If not 0, denotes the desired size of an individual snapshot (unless the per-connection NetworkStreamSnapshotTargetSize component is present). If zero, Unity.Networking.Transport.NetworkParameterConstants.MTU is used (minus headers).
Declaration
[Tooltip("- If zero (the default), NetworkParameterConstants.MTU is used (minus headers).\n\n - Otherwise, denotes the desired size of an individual snapshot (unless the per-connection NetworkStreamSnapshotTargetSize component is present).")]
[Range(0, 1400)]
public int DefaultSnapshotPacketSize
Field Value
Type | Description |
---|---|
int |
MaxSendChunks
The maximum number of chunks the GhostSendSystem will try to send to a single connection in a single NetworkTickRate snapshot send interval. A chunk will count as sent even if it does not contain any ghosts which needed to be sent (because of relevancy or static optimization). If there are more chunks than this, the least important chunks will not be sent even if there is space in the packet. This can be used to reduce / control CPU time on the server.
Declaration
[Tooltip("The maximum number of chunks the GhostSendSystem will try to send to a single connection in a single NetworkTickRate snapshot send interval. A chunk will count as sent even if it does not contain any ghosts which needed to be sent (because of relevancy or static optimization).\n\nDefaults to 0 (OFF).\n\nIf there are more chunks than this, the least important chunks will not be sent even if there is space in the packet. This can be used to reduce / control CPU time on the server.")]
[Min(0)]
public int MaxSendChunks
Field Value
Type | Description |
---|---|
int |
Remarks
Note: MaxSendChunks limits the number of chunks we process, and this filtering is applied BEFORE we check if ghosts are irrelevant. Therefore, if MaxSendChunks is 4 (for example), and the 4 highest importance chunks ONLY contain irrelevant ghosts, we will NOT send any ghosts in this snapshot. If this is undesirable, you can correct this by tweaking the multiplier for irrelevant chunks (see IrrelevantImportanceDownScale) so that they are rarely the most important chunks.
MaxSendEntities
The maximum number of entities the system will try to send to a single connection in a single NetworkTickRate snapshot send interval. An entity will count even if it is not actually sent (because of relevancy or static optimization). If there are more chunks than this, the least important chunks will not be sent even if there is space in the packet. This can be used to reduce / control CPU time on the server.
Declaration
[Tooltip("The maximum number of entities the system will try to send to a single connection in a single NetworkTickRate snapshot send interval. An entity will count even if it is not actually sent (because of relevancy or static optimization).\n\nDefaults to 0 (OFF).\n\nIf there are more chunks than this, the least important chunks will not be sent even if there is space in the packet. This can be used to reduce / control CPU time on the server.")]
[Min(0)]
public int MaxSendEntities
Field Value
Type | Description |
---|---|
int |
MinDistanceScaledSendImportance
The minimum importance considered for inclusion in a snapshot after applying distance based priority scaling to the ghost chunk. Any ghost chunk with a downscaled importance value lower than this will not be added to the snapshot, even if there is enough space in the packet.
Declaration
[Tooltip("The minimum importance considered for inclusion in a snapshot after applying distance based priority scaling to the ghost chunk. Any ghost chunk with a downscaled importance value lower than this will not be added to the snapshot, even if there is enough space in the packet.\n\nDefaults to 0 (OFF).")]
[Min(0)]
public int MinDistanceScaledSendImportance
Field Value
Type | Description |
---|---|
int |
MinSendImportance
The minimum importance considered for inclusion in a snapshot. Any ghost chunk with an importance value lower than this value will not be added to the snapshot, even if there is enough space in the packet.
Declaration
[Tooltip("The minimum importance considered for inclusion in a snapshot. The Defaults to 0 (disabled).\n\nAny ghost chunk with an importance value lower than this value will not be added to the snapshot, even if there is enough space in the packet. Use to reduce send-rate for low-importance ghosts.\n\nDefaults to 0 (OFF).")]
[Min(0)]
public int MinSendImportance
Field Value
Type | Description |
---|---|
int |
Remarks
Counted on a per-connection, per-chunk basis, where importance increases by the Importance value every tick, until sent (NOT confirmed delivered). E.g. Value=60, SimulationTickRate=60, GhostAuthoringComponent.Importance=1 implies a ghost will be replicated roughly once per second.
Properties
EnablePerComponentProfiling
Enable profiling scopes for each component in a ghost. This can help track down why a ghost is expensive to serialize - but it comes with a performance cost, so is not enabled by default.
Declaration
public bool EnablePerComponentProfiling { get; set; }
Property Value
Type | Description |
---|---|
bool |
FirstSendImportanceMultiplier
Non-zero values for MinSendImportance can cause both: a) 'unchanged chunks that are "new" to a new-joiner' and b) 'newly spawned chunks' to be ignored by the replication priority system for multiple seconds. If this behaviour is undesirable, set this to be above MinSendImportance. This multiplies the importance value used on those "new" (to the player or to the world) ghost chunks. Note: This does not guarantee delivery of all "new" chunks, it only guarantees that every ghost chunk will get serialized and sent at least once per connection, as quickly as possible (e.g. assuming you have the bandwidth for it).
Declaration
public uint FirstSendImportanceMultiplier { get; set; }
Property Value
Type | Description |
---|---|
uint |
ForcePreSerialize
Debug Feature: Force all ghosts to use pre-serialization. This means part of the serialization will be done once for all connection, instead of once per-connection. This can increase CPU time for simple ghosts and ghosts which are rarely sent. This switch is meant as a DEBUG feature, providing a way of measuring which ghosts would benefit from using pre-serialization.
Declaration
public bool ForcePreSerialize { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Should not be enabled in Production!
ForceSingleBaseline
Force all ghosts to use a single snapshot delta-compression value prediction baseline. This will reduce CPU usage at the expense of increased bandwidth usage. This is mostly meant as a way of measuring which ghosts should use static optimization instead of dynamic. If the bits / ghost does not significantly increase when enabling this the ghost can use static optimization to save CPU.
Declaration
public bool ForceSingleBaseline { get; set; }
Property Value
Type | Description |
---|---|
bool |
IrrelevantImportanceDownScale
Value used to scale down the importance of chunks where all entities were irrelevant last time it was sent. The importance is divided by this value. It can be used together with MinSendImportance to make sure relevancy is not updated every frame for things with low importance.
Declaration
public int IrrelevantImportanceDownScale { get; set; }
Property Value
Type | Description |
---|---|
int |
KeepSnapshotHistoryOnStructuralChange
Try to keep the snapshot history buffer for an entity when there is a structural change. Doing this will require a lookup and copy of data whenever a ghost has a structural change, which will add additional CPU cost on the server. Keeping the snapshot history will not always be possible, so, this flag does no give a 100% guarantee, and you are expected to measure CPU and bandwidth when changing this.
Declaration
public bool KeepSnapshotHistoryOnStructuralChange { get; set; }
Property Value
Type | Description |
---|---|
bool |
TempStreamInitialSize
Value used to set the initial size of the internal temporary stream in which ghost data is serialized. Using a small size will incur in extra serialization costs (because of multiple round of serialization), while using a larger size provide better performance (overall). The minimum size of this buffer is forced to be the initial capacity of the outgoing data stream (usually MaxMessageSize or larger for fragmented payloads). The suggested default (8kb), while extremely large in respect to the packet size, would allow the GhostSendSystem to be able to to write a large range of mid/small ghost entities types, with varying size (up to hundreds of bytes each), without incurring in extra serialization overhead.
Declaration
public int TempStreamInitialSize { get; set; }
Property Value
Type | Description |
---|---|
int |
UseCustomSerializer
When set, enables support for using any registered GhostPrefabCustomSerializer to serialize ghost chunks.
Declaration
public int UseCustomSerializer { get; set; }
Property Value
Type | Description |
---|---|
int |