Class GhostAuthoringComponent
The GhostAuthoringComponent is the main entry point to configure and create replicated ghosts types. The component must be added only to the GameObject hierarchy root.
It allows setting all ghost properties, such as the replication mode SupportedGhostModes, bandwidth optimization strategy (OptimizationMode, the ghost Importance (how frequently is sent) and others).
GhostAuthoringInspectionComponentInherited Members
Namespace: Unity.NetCode
Syntax
[RequireComponent(typeof(LinkedEntityGroupAuthoring))]
[DisallowMultipleComponent]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.netcode@latest/index.html?subfolder=/api/Unity.NetCode.GhostAuthoringComponent.html")]
public class GhostAuthoringComponent : MonoBehaviour
Fields
DefaultGhostMode
The ghost mode used if you do not manually change it using a GhostSpawnClassificationSystem. If set to OwnerPredicted the ghost will be predicted on the client which owns it and interpolated elsewhere. You must not change the mode using a classification system if using owner predicted.
Declaration
[Tooltip("The `GhostMode` used when first spawned (assuming you do not manually change it, using a GhostSpawnClassificationSystem).\n\nIf set to 'Owner Predicted', the ghost will be 'Predicted' on the client which owns it, and 'Interpolated' on all others. If using 'Owner Predicted', you cannot change the ghost mode via a classification system.")]
public GhostMode DefaultGhostMode
Field Value
Type | Description |
---|---|
GhostMode |
ForcePrefabConversion
Force the ghost baker to treat this GameObject as if it was a prefab. This is used if you want to programmatically create a ghost prefab as a GameObject and convert it to an Entity prefab with ConvertGameObjectHierarchy.
Declaration
[NonSerialized]
public bool ForcePrefabConversion
Field Value
Type | Description |
---|---|
Boolean |
GhostGroup
Add a GhostGroup component which makes it possible for this entity to be the root of a ghost group.
Declaration
[Tooltip("Add a `GhostGroup` component, which makes it possible for this entity to be the root of a 'Ghost Group'.\n\nA 'Ghost Group' is a collection of ghosts who must always be replicated in the same snapshot, which is useful (for example) when trying to keep an item like a weapon in sync with the player carrying it.\n\nTo use this feature, you must add the target ghost entity to this `GhostGroup` buffer at runtime (e.g. when the weapon is first picked up by the player).\n\n<i>Note that GhostGroups slow down serialization, as they force entity chunk random-access. Therefore, prefer other solutions.</i>")]
public bool GhostGroup
Field Value
Type | Description |
---|---|
Boolean |
HasOwner
Add a GhostOwner tracking which connection owns this component. You must set the GhostOwner to a valid NetworkId.Value at runtime.
Declaration
[Tooltip("Automatically adds a `GhostOwner`, which allows the server to set (and track) which connection owns this ghost. In your server code, you must set the `GhostOwner` to a valid `NetworkId.Value` at runtime.")]
public bool HasOwner
Field Value
Type | Description |
---|---|
Boolean |
Importance
If not all ghosts can fit in a snapshot only the most important ghosts will be sent. Higher importance means the ghost is more likely to be sent.
Declaration
[Tooltip("Importance determines which ghosts are selected to be added to the snapshot, in the case where there is not enough space to include all ghosts in the snapshot. Many caveats apply, but generally, higher values are sent more frequently.\n\n<i>Example: A 'Player' ghost with an Importance of 100 is roughly 100x more likely to be sent in any given snapshot than a 'Barrel' ghost with an Importance of 1. In other words, expect the 'Player' ghost to have been replicated 100 times for every one time the 'Barrel' is replicated.</i>\n\nApplied at the chunk level.")]
public int Importance
Field Value
Type | Description |
---|---|
Int32 |
OptimizationMode
This setting is only for optimization, the ghost will be sent when modified regardless of this setting. Optimizing for static makes snapshots slightly larger when they change, but smaller when they do not change.
Declaration
[Tooltip("Bandwidth and CPU optimization:\n\n - <b>Static</b> - This ghost will only be added to a snapshot when its ghost values actually change.\n<i>Examples: Barrels, trees, dropped items, asteroids etc.</i>\n\n - <b>Dynamic</b> - This ghost will be replicated at a regular interval, regardless of whether or not its values have changed, allowing for more aggressive compression.\n<i>Examples: Character controllers, missiles, important gameplay items like CTF flags and footballs etc.</i>\n\n<i>Marking a ghost as `Static` makes snapshots slightly larger when replicated values change, but smaller when they do not.</i>")]
public GhostOptimizationMode OptimizationMode
Field Value
Type | Description |
---|---|
GhostOptimizationMode |
SupportAutoCommandTarget
Automatically send all ICommandData buffers if the ghost is owned by the current connection, AutoCommandTarget.Enabled is true and the ghost is predicted.
Declaration
[Tooltip("Automatically sends all `ICommandData` buffers when the following conditions are met: \n\n - The ghost is owned by the current connection.\n\n - AutoCommandTarget is added, and Enabled is true.\n\n - The ghost is predicted.")]
public bool SupportAutoCommandTarget
Field Value
Type | Description |
---|---|
Boolean |
SupportedGhostModes
The ghost modes supported by this ghost. This will perform some more optimizations at authoring time but make it impossible to change ghost mode at runtime.
Declaration
[Tooltip("Every `GhostMode` supported by this ghost. Setting this to either 'Predicted' or 'Interpolated' will allow NetCode to perform some more optimizations at authoring time. However, it makes it impossible to change ghost mode at runtime.")]
public GhostModeMask SupportedGhostModes
Field Value
Type | Description |
---|---|
GhostModeMask |
TrackInterpolationDelay
Add a CommandDataInterpolationDelay component so the interpolation delay of each client is tracked. This is used for server side lag-compensation.
Declaration
[Tooltip("Add a `CommandDataInterpolationDelay` component so the interpolation delay of each client is tracked.\n\nThis is used for server side lag-compensation (it allows the server to more accurately estimate how far behind your interpolated ghosts are, leading to better hit registration, for example).\n\nThis should be enabled if you expect to use input commands (from this 'Owner Predicted' ghost) to interact with other, 'Interpolated' ghosts (example: shooting or hugging another 'Player').")]
public bool TrackInterpolationDelay
Field Value
Type | Description |
---|---|
Boolean |
UsePreSerialization
Force this ghost to be quantized and copied to the snapshot format once for all connections instead of once per connection. This can save CPU time in the ghost send system if the ghost is almost always sent to at least one connection, and it contains many serialized components, serialized components on child entities or serialized buffers. A common case where this can be useful is the ghost for the character / player.
Declaration
[Tooltip("CPU optimization that forces this ghost to be quantized and copied to the snapshot format <b>once for all connections</b> (instead of once <b>per connection</b>). This can save CPU time in the `GhostSendSystem` assuming all of the following:\n\n - The ghost contains many serialized components, serialized components on child entities, or serialized buffers.\n\n - The ghost is almost always sent to at least one connection.\n\n<i>Example use-cases: Players, important gameplay items like footballs and crowns, global entities like map settings and dynamic weather conditions.</i>")]
public bool UsePreSerialization
Field Value
Type | Description |
---|---|
Boolean |
Properties
SupportsSendTypeOptimization
True if we can apply the GhostSendType optimization on this Ghost.
Declaration
public bool SupportsSendTypeOptimization { get; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
GetAndValidateGhostName(out UInt64)
Validate the name of the GameObject prefab.
Declaration
public FixedString64Bytes GetAndValidateGhostName(out ulong ghostNameHash)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | ghostNameHash | Outputs the hash generated from the name. |
Returns
Type | Description |
---|---|
FixedString64Bytes | The FS equivalent of the gameObject.name. |