Namespace Unity.NetCode
Classes
ClientAndServerInitializationSystemGroup
ClientAndServerSimulationSystemGroup
ClientInitializationSystemGroup
ClientOnlyVariant
Special universal component variant that can be assigned to any component and/or buffer when configuring the GhostComponentSerializerCollectionSystemGroup. Mostly used for stripping components from the server-side ghost prefabs
ClientPopulatePrespawnedGhostsSystem
ClientPopulatePrespawnedGhostsSystem systems is responsible for assign to the pre-spawned ghosts their ghost ids and adding them to the spawned ghosts maps. It relies on the previous initializations step to determine the subscene subset to process.
Clients expect to receive as part ot the protocol:
- subscene hash and baseline hash for validation
- the ghost id range for each subscene.
THE PRESPAWN SUBSCENE SYNC PROTOCOL
Client> will eventually receive the subscene data and will store it into the PrespawnHashElement collection Client> (in parallel, before or after) will serialize the prespawn baseline when a new scene is loaded Client> should validate that:
- the prespawn scenes are present on the server.
- that count, subscene hash and baseline hash match the one on the server Client> will assign the ghost ids to the prespawns Client> must notify the server what scene sections has been loaded and initialized.
ClientPresentationSystemGroup
ClientServerBootstrap
ClientSimulationSystemGroup
ClientTrackLoadedPrespawnSections
The ClientTrackLoadedPrespawnSections is responsible for tracking when a scene section is unloaded and removing the pre-spawned ghosts from the client ghosts maps
CommandDataUtility
CommandReceiveClearSystem
CommandReceiveSystem<TCommandDataSerializer, TCommandData>
CommandReceiveSystemGroup
CommandSendPacketSystem
CommandSendSystem<TCommandDataSerializer, TCommandData>
CommandSendSystemGroup
ConvertToClientServerEntity
DefaultTranslateSmoothingAction.DefaultStaticUserParams
DefaultVariantSystemBase
DefaultVariantSystemBase is an abstract base class that should be used to update the default variants in GhostComponentSerializerCollectionSystemGroup, witch contains what serialization variant to use (GhostComponentVariationAttribute) for certain type. A concrete implementation must implements the RegisterDefaultVariants(Dictionary<ComponentType, Type>) method and add to the dictionary the desired type-variant pairs.
The system must and will be created in both runtime and conversion worlds. During conversion, in particular, the GhostComponentSerializerCollectionSystemGroup is used by the GhostAuthoringConversion to configure the ghost prefabs metadata with the defaults values.
The abstract base class already has the correct flags / update in world attributes set. It is not necessary for the concrete implementation to specify neither the flags or the update in world.
There is also no particular restriction in witch group the system need run into since all data needed by the runtime is created inside the OnCreate method. As a general rule, if you really need to add an UpdateInGroup attribute, please use only the SimulationSystemGroup as target.
DontSerializeForCommandAttribute
Add the attribute to prevent a field ICommandData struct to be serialized
DontSerializeVariant
Special universal component variant that can be assigned to any component and/or buffer. When a component serializer is set to DontSerializeVariant, the component itself is not stripped from the client or server version of the prefab and at runtime it is not serialized and sent to the clients.
DontSupportPrefabOverrides
Use this attribute to prevent a GhostComponent to support any kind of variation.
DontSupportVariationAttribute
Use this attribute to prevent a GhostComponent to support any kind of variation.
DriverMigrationSystem
FinishGhostPhysicsPrediction
GhostAuthoringComponent
GhostAuthoringConversion
GhostCollectionSystem
GhostComponentAttribute
This attribute can be used to tag components to control which ghost prefab variants they are included in and where they are sent for owner predicted ghosts.
GhostComponentSerializerCollectionSystemGroup
GhostComponentSerializerRegistrationSystemBase
GhostComponentUtilities
GhostComponentVariationAttribute
Generate a serialization variantion for a component using the GhostFieldAttribute annotations
present in variant declaration.
The component variant can be assigned at authoring time using the GhostAuthoringComponent editor.
GhostDespawnSystem
GhostDistancePartitioningSystem
GhostFieldAttribute
GhostFieldSubType
Hold a list of constant int that can be used across the project to specify subtype in GhostFieldAttribute. User can expand that list by using an AssemblyDefinitionReference to Unity.NetCode.Gen and adding a partial class that extend and add new constant literals to that class.
GhostInputSystemGroup
GhostOwnerComponentAuthoring
GhostPhysicsPreProcess
GhostPredictionHistorySystem
A system used to make a backup o the current predicted state right after the last full (not fractional) tick in a prediction loop for a frame has been completed. The backup does a memcopy of all components which are rolled back as part of prediction to a separate memory area connected to the chunk. The backup is used to restore the last full tick to continue prediction when no new data has arrived, when that happens only the fields which are actually serialized as part of the snapshot are copied back, not the full component. The backup data is also used to detect errors in the prediction as well as to add smoothing of predicted values.
GhostPredictionSmoothingSystem
GhostPredictionSystemGroup
GhostReceiveSystem
GhostSendSystem
GhostSerializerAttribute
For internal use only. Markup for the generate component/buffer code-generated serializer, added automatically by the code-generation system.
GhostSimulationSystemGroup
GhostSpawnClassificationSystem
The default GhostSpawnClassificationSystem will set the SpawnType to the default specified in the GhostAuthoringComponent, unless some other classification has already set the SpawnType. This system will also check ghost owner to set the spawn type correctly for owner predicted ghosts. For predictive spawning you usually add a system after GhostSpawnClassificationSystem which only looks at items with SpawnType set to Predicted and set the PredictedSpawnEntity if you find a matching entity. The reason to put predictive spawn systems after the default is so the owner predicted logic has run.
GhostSpawnSystem
GhostSpawnSystemGroup
GhostUpdateSystem
GhostVariantsUtility
Collection of utility that are used by the editor and runtime to compute and check ghost component variants hashes
HeartbeatReceiveSystem
HeartbeatReplySystem
HeartbeatSendSystem
NetCodeBufferComponentExtensions
NetCodeDebugConfigAuthoring
NetCodeDisableCommandCodeGenAttribute
This attribute is used to disable code generation for a struct implementing ICommandData or IRpcCommand
NetDebugSystem
NetworkReceiveSystemGroup
NetworkStreamCloseSystem
NetworkStreamReceiveSystem
NetworkTimeSystem
PhysicsWorldHistory
PredictedGhostSpawnSystem
PredictedPhysicsSystemGroup
PrepareGhostPhysicsPrediction
PrespawnGhostSystemGroup
PrespawnSubsceneElementExtensions
ResetPhysicsMotionVelocity
RestorePhysicsVelocity
RpcCommandRequestSystem<TActionSerializer, TActionRequest>
RpcCommandRequestSystemGroup
RpcSystem
ServerInitializationSystemGroup
ServerPopulatePrespawnedGhostsSystem
ServerPopulatePrespawnedGhostsSystem systems is responsible for assign to the pre-spawned ghosts their ghost ids and add add them to the spawn maps. It rely on the previous initialization steps to determine the subscene subset to process.
The server is authoritative and it is responsible for assigning unique id ranges to the each scene. For each section that present prespawn ghosts, the prespawn hash, id range and baseline hash are sent to client as part of the streaming protocol. Clients will use the received subscene hash and baseline hash for validation and the ghost range to assign the ghost id to the pre-spawned ghosts like the server. This remove any necessity for loading order determinism. Finally, clients will ack the server about the loaded scenes and the server, upon ack receipt, will start streaming the pre-spawned ghosts
======================================================================
THE FULL PRESPAWN SUBSCENE SYNC PROTOCOL
Server> calculates the prespawn baselines Server> assign runtime ghost IDs to the prespawned ghosts Server> store the SubSceneHash, BaselineHash and AssignedFirstId, PrespawnCount inside the the PrespawnHashElement collection Server> create a new ghost with a PrespawnSceneLoaded bufffer that is serialized to the clients
Client> will eventually receive the ghost with the subscene list Client> (in parallel or before) will serialize the prespawn baseline when a new scene is loaded Client> should validate that subscene data match Client> will assign the ghost ids to the prespawns Client> will ack the server that the scene has been received and witch sub-set of the scenes must be streamed to him
ServerSimulationSystemGroup
ServerTrackLoadedPrespawnSections
The ServerTrackLoadedPrespawnSections is responsible for tracking when an initialized prespawn sections is unloaded in order to release any allocated data and freeing ghost id ranges.
StorageInfoFromEntityExtensions
SwitchPredictionSmoothingPhysicsOrderingSystem
SwitchPredictionSmoothingSystem
TickClientInitializationSystem
TickClientPresentationSystem
TickClientSimulationSystem
TickServerInitializationSystem
TickServerSimulationSystem
UpdateInWorldAttribute
Structs
AutoCommandTarget
ClientServerTickRate
ClientServerTickRateRefreshRequest
ClientServerWorldAllocatorResetSystem
ClientTickRate
CollisionHistoryBufferRef
CommandDataInterpolationDelay
CommandReceiveSystem<TCommandDataSerializer, TCommandData>.ReceiveJobData
CommandSendSystem<TCommandDataSerializer, TCommandData>.SendJobData
CommandTargetComponent
DefaultTranslateSmoothingAction
DefaultUserParams
DisableAutomaticPrespawnSectionReporting
Singleton component used to enable/disable the built-in scene auto-tracking.
DisconnectReasonEnumToString
DriverMigrationSystem.DriverState
DriverMigrationSystem.WorldState
DynamicTypeList
EnablePacketLogging
GameProtocolVersion
GhostChildEntityComponent
A tag added to child entities in a ghost with multiple entities. It should also be added to ghosts in a group if the ghost is not the root of the group.
GhostCollection
A component used to identify the singleton which owns the ghost collection lists and data. The singleton contains buffers for GhostCollectionPrefab, GhostCollectionPrefabSerializer, GhostCollectionComponentIndex and GhostComponentSerializer.State
GhostCollectionComponentIndex
This list contains the set of entity + component for all serialization rules in GhostCollectionPrefabSerializer. GhostCollectionPrefabSerializer contains a FirstComponent and NumComponents which identifies the set of components to use from this array. Added to the GhostCollection singleton entity.
GhostCollectionComponentType
This list contains the set of uniques component which support serialization. Used to map the DynamicComponentTypeHandle to a concrete ComponentType in jobs. Added to the GhostCollection singleton entity.
GhostCollectionPrefab
A list of all prefabs which can be used for ghosts. This is populated with all ghost prefabs on the server and that list is sent for clients. Having a prefab in this list does not guarantee that there is a serializer for it yet. Added to the GhostCollection singleton entity.
GhostCollectionPrefabSerializer
A list of all serializer data for the prefabs in GhostCollectionPrefab. This list can be shorter if not all serializers are created yet. Added to the GhostCollection singleton entity.
GhostComponent
Component signaling an entity which is replicated over the network
GhostConnectionPosition
GhostDeltaPredictor
GhostDeserializerState
GhostDistanceImportance
Singleton component used to control distance based importance settings
GhostDistancePartition
GhostDistancePartitionShared
GhostGroup
Similar to LinkedEntityGroup, this buffer can be added to the parent ghost, and denotes a group of ghost children that should all be serialized as part of this ghost. Note: LinkedEntityGroup stores the root entity in the list, GhostGroup does not!
GhostOwnerComponent
GhostPrefabMetaData
A BlobAsset containing all the meta data required for ghosts.
GhostPrefabMetaData.ComponentInfo
GhostPrefabMetaData.ComponentReference
GhostPrefabMetaDataComponent
A component added to all ghost prefabs. It contains the meta-data required to use the prefab as a ghost.
GhostPrefabRuntimeStrip
A component added to ghost prefabs which require runtime stripping of components before they can be used. The component is removed when the runtime stripping is performed.
GhostSerializerState
GhostSpawnBuffer
The GhostSpawnBuffer is the data for a GhostSpawnQueueComponent singleton. It contains a list of ghosts which will be spawned by the GhostSpawnSystem at the beginning of next frame. It is populated by the GhostReceiveSystem and there needs to be a classification system updating after the GhostReceiveSystem which sets the SpawnType so the spawn system knows how to spawn the ghost. A classification system should only modify the SpawnType and PredictedSpawnEntity fields of this struct. InternalBufferCapacity allocated to almost max out chunk memory.
GhostSpawnQueueComponent
GhostSPawnQueueComponent is used to identify the singleton component which contains the GhostSpawnBuffer.
GhostTypeComponent
Component storing the guid of the prefab the ghost was created from. This is used to lookup ghost type in a robust way which works even if two ghosts have the same archetype
HeartbeatComponent
IncomingCommandDataStreamBufferComponent
This buffer stores a single incoming command packet. One per NetworkStream (client). A command packet contains commands for CommandSendSystem.k_InputBufferSendSize (default 4) ticks where 3 of them are delta compressed. It also contains some timestamps etc for ping calculations.
IncomingRpcDataStreamBufferComponent
One per NetworkConnection. Stores queued, incoming RPC data. Thus, buffer size is related to inbound-from-server RPC count * size. InternalBufferCapacity is zero as RPC's can vary in size, and we don't want to constantly move the RPC data into and out of the chunk.
IncomingSnapshotDataStreamBufferComponent
One per NetworkConnection. Stores the incoming, yet-to-be-processed snapshot stream data for a connection. Each snapshot is designed to fit inside MTU, so expect this to be MTU or less.
LagCompensationConfig
Singleton entity that allow to configure the NetCode LagCompensation system. If the singleton does not exist the PhysicsWorldHistory system will not run. If you wnat to use PhysicsWorldHistory in a prediction system the config must exist in both client and server worlds, but in the client world HistorySize can be different from the server - usually 1 is enough on the client.
MigrationTicket
NetCodeDebugConfig
NetDebug
NetworkIdComponent
NetworkProtocolVersion
NetworkSnapshotAckComponent
NetworkStreamConnection
NetworkStreamDisconnected
NetworkStreamInGame
NetworkStreamRequestDisconnect
NetworkStreamSnapshotTargetSize
OutgoingCommandDataStreamBufferComponent
This buffer stores a single outgoing command packet without the headers for timestamps and ping. A command packet contains commands for CommandSendSystem.k_InputBufferSendSize (default 4) ticks where 3 of them are delta compressed. It also contains some timestamps etc for ping calculations.
OutgoingRpcDataStreamBufferComponent
One per NetworkConnection. Stores queued, outgoing RPC data. Thus, buffer size is related to client-authored RPC count * size. InternalBufferCapacity is zero as RPC's can vary in size, and we don't want to constantly move the RPC data into and out of the chunk.
PendingSpawnPlaceholderComponent
Component on client signaling that an entity is a placeholder for a not yet spawned ghost rather than a real ghost
PhysicsGraphicalSmoothingDefaultVariant
Default serialization variant for the PhysicsGraphicalSmoothing which disables smoothing on interpolated clients. Ghost are controled by the server rather than physics on interpolated clients, which makes the physics smoothing incorrect.
PhysicsVelocityDefaultVariant
Default serialization variant for the PhysicsVelocity. Necessary to synchronize physics
PortableFunctionPointer<T>
PredictedGhostComponent
Component on client signaling that an entity is predicted instead of interpolated
PredictedGhostSpawn
Added to a 'PredictedGhostSpawnList' singleton entity. Contains a transient list of ghosts that should be pre-spawned. Expects to be handled during the GhostSpawnClassificationSystem step. InternalBufferCapacity allocated to almost max out chunk memory. In practice, this capacity just needs to hold the maximum number of client-authored ghost entities per frame, which is typically in the range 0 - 1.
PredictedGhostSpawnList
PredictedGhostSpawnRequestComponent
Component used to request predictive spawn of a ghost. Create an entity from a prefab in the ghost collection with this tag added. You need to implement a custom spawn classification system in order to use this.
PredictedPhysicsConfig
A component used as a singleton to control the use of physics in ghost prediction. When the singleton exists all physics systems, and systems with ordering contraints against physics systems ([UpdateBefore], [UpdateAfter]) are moved into the ghost prediction system group and run as part of prediction. The singleton must be added on both the client and server with compatible values. When using physics simulation in prediction all dynamic physics objects must be ghosts. When netcode is present it will add a PhysicsMassOverride to all ghosts with dynamic physics on the client, this means it is not possible to use PhysicsMassOverride for game specific purposes on ghosts.
PreSerializedGhost
Adding this component to a ghost will trigger pre-serialization for that ghost. Pre-serialization means that part of the serialization process happens before the regular serialization pass and can be done once for all connections. This can save some CPU time if the the ghost will generally be sent to more than one player every frame and it contains complex serialization (serialized data on child entities or buffers).
PreSpawnedGhostIndex
Unique within a subscene and used to deterministically assign ghost id to pre-spawned ghost entities.
PrespawnGhostBaseline
Buffer added during conversion to all the ghost with a PrespawnId component The buffer will contains the a pre-serialized ghost snapshot, generated at the time the PrespawnGhostBaselineSystem process the entity. The Prespawn baselines are used for bandwidth optimization for late joining player. The server will send only the prespawn ghost that has changed in respect to that baseline to the new client.
PrespawnGhostIdRange
Added to the PrespawnGhostIdAllocator singleton entity. GhostId allocation map for prespawn object. Used by the server to track the subset of ghost ids that are associated to a scene that contains prespawned ghosts. InternalBufferCapacity is set to (approximately) max out the chunk.
PrespawnGhostSerializer
Build the ghost baseline for all the pre-spawned ghosts present in the world. The job will add to the entities a new buffer, PrespawGhostBaseline, witch will contains the a pre-serialized snapshot of the entity at the time the job run.
NOTE: The serialization does not depend on component stripping (it is only dependent on the ghost type archetype serializer /omponent that is guarantee to be same on both client and server and that is handled by the GhostCollectionSystem)
PrespawnSceneLoaded
For each loaded and process subscene, the server authoritatively populate this buffer. The client will receive it as part of the snapshot stream and will use the information to correctly process any matching loaded subscene. Hash are used to verify on the client that everything match the server to correctly use the prefab baseline optimization. InternalBufferCapacity allocated to almost max out chunk memory.
PrespawnSectionAck
Component added by the server to to the NetworkStream entity. Used to track witch prespawned ghost sections has been loaded/acked by the client. The server streams prespawned ghost only for the sections that as been notified ready by the client.
PrespawnsSceneInitialized
Added to SubScene entity when all the baselines and the pre-spawned ghosts has been processed.
ReceiveRpcCommandRequestComponent
RelevantGhostForConnection
RotationDefaultVariant
RpcCommandRequestSystem<TActionSerializer, TActionRequest>.SendRpcData
RpcDeserializerState
RpcExecutor
RpcExecutor.Parameters
RpcQueue<TActionSerializer, TActionRequest>
RpcSerializerState
SendRpcCommandRequestComponent
SharedGhostTypeComponent
Component used on the server to make sure ghosts of difference ghost types are in different chunks even if they have the same archetype (but different data)
SnapshotData
SnapshotData.DataAtTick
SnapshotDataBuffer
A data structure used to store ghosts snapshot buffers data content. Typically around 1-12kb per entity. Thus, we always allocate on the heap.
SnapshotDynamicBuffersHelper
Helper class for managing ghost buffers data
SnapshotDynamicDataBuffer
A data structure used to store ghosts dynamic buffers data content. BeginArray(SnapshotHistorySize] uint dataSize, (16 bytes aligned) current serialized data length for each slot. Used for delta compression EndArray BeginArray(SnapshotHistorySize] for each buffers: uint[maskBits] elements change bitmask byte[numElements] serialized buffers data EndArray The buffer grow in size as necessary to accomodate new data. All slots have the same size, usually larger than the data size. The serialized element size is aligned to the 16 bytes boundary
SpawnedGhost
StartStreamingSceneGhosts
StopStreamingSceneGhosts
SubSceneGhostComponentHash
The hash of all the ghost component data which exists in the scene. This can be used to sort the subscenes so the ghost IDs of the pre-spawned scene objects line up deterministically.
SubScenePrespawnBaselineResolved
Tag component added to subscene entity when the prespawn baselines has been serialized.
SubSceneWithPrespawnGhosts
Added during conversion to all subscenes that contains pre-spawned ghosts.
SwitchPredictionSmoothing
SwitchPredictionSmoothingPhysicsOrderingSystem.Disabled
ThinClientComponent
TranslationDefaultVariant
VariantType
Interfaces
ICommandData
Commands (usually inputs) that must be sent from client to server to control an entity (or any other thing) should implement the ICommandData interface. Prefer using the ICommandData over Rpc if you need to send a constant stream of data from client to server
ICommandData, being a subclass of IBufferElementData, can also be serialized from server to the clients and natively support the presence of GhostComponentAttribute and GhostFieldAttribute. As such, the same rule for buffers apply: if the command buffer must be serialized, then all fields must be annotated with a GhostFieldAttribute. Failure to do so will generate code-generation errors.
However, differently from normal component, ICommandData buffers are not serialized to all the clients by default. In particular, in absence of a GhostComponentAttribute governing the serialization behavior the following set of options are set: PrefabType is set to All. The buffer is present on all the ghost variant. OwnerPredictedSendType is set to Predicted. Only predicted ghost can receive the buffer and interpolated variant will have the component stripped or disabled. OwnerSendType is set to SendToNonOwner. If the ghost has an owner, is sent only to the clients who don't own the ghost.
Is generally not recommended to send back to the ghost owner its own commands. For that reason, setting the SendToOwner flag will be reported as a error and ignored. Also, because they way ICommandData works, some care must be used when setting the PrefabType property:
- Server: While possible, does not make much sense. A warning will be reported.
- Clients: The ICommandData buffer is stripped from the server ghost. A warning will be reported
- InterpolatedClient: ICommandData buffers are stripped from the server and predicted ghost. A warning will be reported
- Predicted: ICommandData buffers are stripped from the server and predicted ghost. A warning will be reported.
- AllPredicted: Interpolated ghost will not have the command buffer.
- All: All ghost will have the command buffer.
ICommandDataSerializer<T>
IGhostMappingSystem
INetworkStreamDriverConstructor
IRpcCommand
IRpcCommandSerializer<T>
Enums
ClientServerBootstrap.PlayType
ClientServerTickRate.FrameRateMode
Enum to control how the simulation should deal with running at a higher frame rate than simulation rate.
ConvertToClientServerEntity.ConversionTargetType
GhostAuthoringComponent.GhostMode
GhostAuthoringComponent.GhostModeMask
GhostAuthoringComponent.GhostOptimizationMode
GhostCollectionPrefab.LoadingState
GhostPrefabMetaData.GhostMode
GhostPrefabType
GhostRelevancyMode
GhostSendType
GhostSpawnBuffer.Type
NetDebug.LogLevelType
NetworkStreamDisconnectReason
NetworkStreamProtocol
RpcSystem.ErrorCodes
SendToOwnerType
SmoothingAction
Denotes how GhostFieldAttribute values are deserialized when received from snapshots.