Skip to content

Game.Prefabs.TutorialAutoActivation

Assembly:
Assembly-CSharp (typical Unity/CS mod assembly; adjust if different in your project)

Namespace:
Game.Prefabs

Type:
class

Base:
TutorialActivation

Summary:
TutorialAutoActivation is a prefab component used by the tutorial system to automatically enable or require a prefab unlock before activating a tutorial. It exposes an optional PrefabBase reference (m_RequiredUnlock) that, if set, is converted to an Entity during prefab initialization and stored in the AutoActivationData component on the prefab entity. The component ensures the required unlock prefab is reported as a dependency so it is available at load/initialization time.


Fields

  • public PrefabBase m_RequiredUnlock
    Holds an optional reference to a prefab that must be unlocked/available before the tutorial auto-activation can proceed. Marked with [CanBeNull] — null means no unlock requirement. During LateInitialize this PrefabBase is resolved to an Entity (or Entity.Null) and stored in the AutoActivationData component on the prefab entity.

Properties

  • (none declared directly on this class)

Constructors

  • public TutorialAutoActivation()
    Default (parameterless) constructor — not defined explicitly in source, provided by the compiler. No special construction logic in this class.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds the m_RequiredUnlock prefab to the provided dependency list (if it is non-null), and calls the base implementation. This ensures the required unlock prefab is loaded/available when this prefab is processed.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    No-op in this class (intentionally left empty). This means the class does not add any ECS archetype-level component types at this stage.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Calls the base implementation, then adds ComponentType.ReadWrite() to the provided set. This signals that prefab entities for this prefab will include the AutoActivationData component (writable).

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Performs runtime initialization for the created prefab entity:

  • Calls the base LateInitialize.
  • Retrieves the PrefabSystem from the entity manager's world via GetExistingSystemManaged().
  • Resolves m_RequiredUnlock (if non-null) to an Entity using PrefabSystem.GetEntity; otherwise uses Entity.Null.
  • Writes an AutoActivationData struct to the prefab entity with m_RequiredUnlock set to that resolved Entity.

Notes: - The AutoActivationData component is expected to be an ECS IComponentData (likely a struct) containing an Entity field named m_RequiredUnlock; this is what the prefab receives so runtime systems can check the required unlock state. - The class depends on PrefabSystem being present in the world to convert PrefabBase references to Entities.

Usage Example

// Typical behavior is handled by the prefab pipeline; you usually set m_RequiredUnlock
// in the prefab inspector (or via prefab authoring code). The prefab system will call
// LateInitialize to write the AutoActivationData component on the prefab entity.

[ComponentMenu("Tutorials/Activation/", new Type[] { typeof(TutorialPrefab), typeof(TutorialListPrefab) })]
public class TutorialAutoActivation : TutorialActivation
{
    [CanBeNull]
    public PrefabBase m_RequiredUnlock;

    public override void LateInitialize(EntityManager entityManager, Entity entity)
    {
        base.LateInitialize(entityManager, entity);
        PrefabSystem prefabSystem = entityManager.World.GetExistingSystemManaged<PrefabSystem>();
        Entity requiredEntity = Entity.Null;
        if (m_RequiredUnlock != null)
            requiredEntity = prefabSystem.GetEntity(m_RequiredUnlock);

        entityManager.SetComponentData(entity, new AutoActivationData
        {
            m_RequiredUnlock = requiredEntity
        });
    }
}

Additional information: - Attribute: [ComponentMenu("Tutorials/Activation/", new Type[] { typeof(TutorialPrefab), typeof(TutorialListPrefab) })] — places this component in the prefab authoring menu under Tutorials/Activation and associates it with TutorialPrefab and TutorialListPrefab types. - The [CanBeNull] annotation on m_RequiredUnlock documents that the field may be left unset. If null, AutoActivationData.m_RequiredUnlock will be Entity.Null and runtime activation logic should treat it as "no prerequisite". - If you need the prefab to include other runtime components for activation logic, add them in GetPrefabComponents or through the prefab authoring pipeline.