docs.unity3d.com
    Show / Hide Table of Contents

    Class GhostPrefabCreation

    Helper methods and structs used to configure and create ghost prefabs

    Inheritance
    Object
    GhostPrefabCreation
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.NetCode
    Syntax
    public static class GhostPrefabCreation

    Methods

    CollectAllComponents(EntityManager, NativeArray<Entity>, out NativeList<ComponentType>, out NativeArray<Int32>)

    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<Int32> componentCounts

    Populated with each ghost's number of components.

    ConvertToGhostPrefab(EntityManager, Entity, GhostPrefabCreation.Config, NativeParallelHashMap<GhostPrefabCreation.Component, GhostPrefabCreation.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(NativeParallelHashMap<GhostPrefabCreation.Component, GhostPrefabCreation.ComponentOverride>))
    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(GhostPrefabCreation.Config, EntityManager, Entity, GhostType, NativeArray<Entity>, NativeList<ComponentType>, NativeArray<Int32>, 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 rootEntity

    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 rootEntity

    NativeList<ComponentType> allComponents

    List of all component types.

    NativeArray<Int32> componentCounts

    List of number of components on each index.

    NetcodeConversionTarget target NetcodeConversionTarget
    NativeArray<GhostPrefabType> prefabTypes

    List of different types of GhostPrefabType to created.

    In This Article
    • Methods
      • CollectAllComponents(EntityManager, NativeArray<Entity>, out NativeList<ComponentType>, out NativeArray<Int32>)
      • ConvertToGhostPrefab(EntityManager, Entity, GhostPrefabCreation.Config, NativeParallelHashMap<GhostPrefabCreation.Component, GhostPrefabCreation.ComponentOverride>)
      • FinalizePrefabComponents(GhostPrefabCreation.Config, EntityManager, Entity, GhostType, NativeArray<Entity>, NativeList<ComponentType>, NativeArray<Int32>, NetcodeConversionTarget, NativeArray<GhostPrefabType>)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023