Skip to content

Game.Prefabs.ContentPrerequisite

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Component placed on a prefab to declare another ContentPrefab as a prerequisite. During prefab conversion this component adds a ContentPrerequisiteData component to the resulting ECS entity that references the prerequisite prefab's entity. The component also contributes the prerequisite prefab to the prefab dependency list and declares the ECS component required for the prefab archetype. The class is marked with [HideInEditor] and appears in the component menu under "Prefabs/Content/".


Fields

  • public ContentPrefab m_ContentPrerequisite
    Reference to the ContentPrefab that this prefab requires. Assigned in the prefab (editor). During LateInitialize this is resolved to an Entity and stored into the entity's ContentPrerequisiteData component.

Properties

  • This type does not declare any C# properties.

Constructors

  • public ContentPrerequisite()
    Default parameterless constructor (no explicit initialization in source). Instances are normally created/managed by the prefab system / Unity when loading prefabs.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds the referenced m_ContentPrerequisite to the provided prefabs list (calls base.GetDependencies first). This ensures the prerequisite prefab is included in the build/load order for the prefab that declares it.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Declares that the prefab's ECS representation requires a read/write ContentPrerequisiteData component by adding ComponentType.ReadWrite() to the set. This causes the prefab entity to include that component.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Empty override — this component does not add additional archetype components beyond what GetPrefabComponents declares.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    If m_ContentPrerequisite is not null, resolves the referenced ContentPrefab to its ECS Entity using the PrefabSystem and writes a ContentPrerequisiteData component to the given entity with that Entity reference. This is executed during prefab conversion/initialization so runtime systems can rely on the ECS component rather than the authoring reference.

Usage Example

// Authoring: assign a ContentPrefab in the inspector to m_ContentPrerequisite.
// During conversion LateInitialize will run and write ContentPrerequisiteData to the prefab entity.

public class ExampleUsage
{
    public void ReadPrerequisite(EntityManager em, Entity prefabEntity)
    {
        if (em.HasComponent<ContentPrerequisiteData>(prefabEntity))
        {
            var data = em.GetComponentData<ContentPrerequisiteData>(prefabEntity);
            Entity requiredEntity = data.m_ContentPrerequisite;
            // Use requiredEntity (e.g., check if loaded or inspect its components)
        }
    }
}

Notes: - The component is intended for prefab-time setup; runtime code should use the ContentPrerequisiteData ECS component to access the prerequisite entity. - The class uses PrefabSystem.GetEntity(...) to resolve a ContentPrefab authoring reference to an ECS Entity. If m_ContentPrerequisite is null, no component is written.