Skip to content

Game.AreaSubObjects

Assembly:
Game (Assembly-CSharp)
{{ This component is part of the game's main assembly (commonly Assembly-CSharp in Unity projects). }}

Namespace:
Game.Prefabs

Type:
public class

Base:
ComponentBase

Summary:
AreaSubObjects is a ComponentBase used by area prefabs to reference a list of sub-object prefabs (AreaSubObjectInfo). It exposes an array of sub-object definitions that are added to prefab dependency resolution and registers the runtime SubObject component type for the prefab. The class is annotated with a ComponentMenu attribute ("Areas/") targeting AreaPrefab so it appears in the editor component menu for area prefabs. Note: the code enumerates m_SubObjects without a null check, so m_SubObjects should be initialized (empty array if necessary) to avoid NullReferenceException.


Fields

  • public AreaSubObjectInfo[] m_SubObjects
    {{ Array of sub-object definitions used by this area prefab. Each AreaSubObjectInfo contains a reference (m_Object) to a PrefabBase that will be added to dependency lists. Ensure this array is non-null (use an empty array rather than null) to avoid runtime exceptions when GetDependencies iterates it. }}

Properties

  • public override bool ignoreUnlockDependencies => true
    {{ This component opts out of unlock-dependency checking by returning true. That means the presence of this component will not add unlock requirements to the prefab's unlock dependency set. Use this when the sub-objects should not affect the prefab unlocking logic. }}

Constructors

  • public AreaSubObjects()
    {{ Implicit default constructor. No special initialization is performed by the class; if you need an empty array for m_SubObjects to avoid null checks, initialize it after construction or ensure the serialized asset contains an empty array. }}

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    {{ Adds the referenced sub-object prefabs to the provided dependency list. Implementation calls base.GetDependencies(prefabs) then iterates m_SubObjects and adds each m_Object to the prefabs list. Because the method assumes m_SubObjects is non-null, ensure it is initialized (e.g., empty array) to prevent NullReferenceException. This is used by prefab building/loading to ensure referenced prefabs are available. }}

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    {{ Registers the runtime component type required by these sub-objects. Specifically, it adds ComponentType.ReadWrite() to the components set. This ensures the Entity archetype created for the prefab includes the SubObject component. }}

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    {{ Empty override — no additional archetype components beyond those added in GetPrefabComponents. This method is intentionally left blank. }}

Usage Example

// Example: ensure the AreaSubObjects component has an initialized array and that dependencies are collected.
var areaSub = new AreaSubObjects();
areaSub.m_SubObjects = new AreaSubObjectInfo[0]; // avoid null

// During prefab dependency collection:
var deps = new List<PrefabBase>();
areaSub.GetDependencies(deps);

// During prefab component registration:
var compTypes = new HashSet<ComponentType>();
areaSub.GetPrefabComponents(compTypes);