Class GhostPrefabCreation
Helper methods and structs used to configure and create ghost prefabs
Inherited Members
Namespace: Unity.NetCode
Assembly: Unity.NetCode.dll
Syntax
public static class GhostPrefabCreation
Methods
CollectAllComponents(EntityManager, NativeArray<Entity>, out NativeList<ComponentType>, out NativeArray<int>)
Helper method to build a list of all component types on all children of a ghost prefab, should not be called directly.
Declaration
public static void CollectAllComponents(EntityManager entityManager, NativeArray<Entity> linkedEntities, out NativeList<ComponentType> allComponents, out NativeArray<int> componentCounts)
Parameters
Type | Name | Description |
---|---|---|
EntityManager | entityManager | Used to add components data on ghost children. |
NativeArray<Entity> | linkedEntities | Linked entities, 0 is the root followed by its children. Each will be marked with GhostChildEntity |
NativeList<ComponentType> | allComponents | Populated with root and child components. |
NativeArray<int> | componentCounts | Populated with each ghost's number of components. |
ConvertHash128ToUUID5(Hash128)
Convert a general Unity.Entities.Hash128 to a proper UUID5 hash format by enforcing bits and version to be set.
Declaration
public static Hash128 ConvertHash128ToUUID5(Hash128 hash128)
Parameters
Type | Name | Description |
---|---|---|
Hash128 | hash128 | the hash to convert to UUID5 format |
Returns
Type | Description |
---|---|
Hash128 | a new hash with the appropriate bytes set as specified by the RFC 4122 |
ConvertToGhostPrefab(EntityManager, Entity, Config, NativeParallelHashMap<Component, ComponentOverride>)
Converts an entity to a ghost prefab, and registers it with the collection.
This method will add the Prefab
and LinkedEntityGroup
components if they do not already exist.
It will also add all component required for a prefab to be used as a ghost, and register it with the GhostCollectionSystem
.
The blob asset (which is created as part of making it a ghost prefab) is owned (and will be freed by) the GhostCollectionSystem
.
Thus, the calling code should not free the blob asset.
The prefabs must be created exactly the same way on both the client and the server, and they must contain all components.
Use component overrides if you want to have some components server or client only.
Declaration
public static void ConvertToGhostPrefab(EntityManager entityManager, Entity prefab, GhostPrefabCreation.Config config, NativeParallelHashMap<GhostPrefabCreation.Component, GhostPrefabCreation.ComponentOverride> overrides = default)
Parameters
Type | Name | Description |
---|---|---|
EntityManager | entityManager | Used to add components data on ghost children. |
Entity | prefab | Entity prefab to be converted. |
GhostPrefabCreation.Config | config | Configuration used to create a ghost prefab. |
NativeParallelHashMap<GhostPrefabCreation.Component, GhostPrefabCreation.ComponentOverride> | overrides | Override types for specific components. |
Remarks
Note that - when using this in a System OnCreate
method - you must ensure your system is created after the DefaultVariantSystemGroup
,
as we must register serialization strategies before you access them.
FinalizePrefabComponents(Config, EntityManager, Entity, GhostType, NativeArray<Entity>, NativeList<ComponentType>, NativeArray<int>, NetcodeConversionTarget, NativeArray<GhostPrefabType>)
Strip components which are not used, and add the ones which should always be present on a ghost prefab
Declaration
public static void FinalizePrefabComponents(GhostPrefabCreation.Config ghostConfig, EntityManager entityManager, Entity rootEntity, GhostType ghostType, NativeArray<Entity> linkedEntities, NativeList<ComponentType> allComponents, NativeArray<int> componentCounts, NetcodeConversionTarget target, NativeArray<GhostPrefabType> prefabTypes)
Parameters
Type | Name | Description |
---|---|---|
GhostPrefabCreation.Config | ghostConfig | Configuration used when creating ghost prefabs. |
EntityManager | entityManager | Used to validate which components exists on |
Entity | rootEntity | Components existing on this entity, like GhostOwner is used to configure the result. |
GhostType | ghostType | Component storing the guid of the prefab the ghost was created from. |
NativeArray<Entity> | linkedEntities | List of all linked entities to the |
NativeList<ComponentType> | allComponents | List of all component types. |
NativeArray<int> | componentCounts | List of number of components on each index. |
NetcodeConversionTarget | target | |
NativeArray<GhostPrefabType> | prefabTypes | List of different types of GhostPrefabType to created. |