Skip to content

Game.Zones.LoadSystem

Assembly:
Assembly-CSharp.dll

Namespace:
Game.Zones

Type:
class

Base:
Game.Common.GameSystemBase

Summary:
LoadSystem is a small game ECS system used during zone loading. On creation it finds the game's LoadGameSystem and creates an EntityQuery for entities that have the Block component. The system is only enabled to run when that query has matching entities. During update it inspects the load context (via LoadGameSystem) and, if the current load purpose is Purpose.NewGame, it marks matching zone Block entities with the Updated component so they are treated as initialized in a new-game scenario. The class methods are annotated with [Preserve] to avoid stripping.


Fields

  • private LoadGameSystem m_LoadGameSystem
    Reference to the LoadGameSystem instance retrieved from the World. Used to read the current load context/purpose (e.g., Purpose.NewGame).

  • private Unity.Entities.EntityQuery m_EntityQuery
    EntityQuery that targets entities containing the Block component. The system calls RequireForUpdate(m_EntityQuery) so the system only runs when such entities exist.

Properties

  • None

Constructors

  • public LoadSystem()
    Default parameterless constructor. Marked with [Preserve] in source; present so the system can be created/managed by the ECS runtime and to avoid removal by code stripping.

Methods

  • protected override void OnCreate() : System.Void
    Called when the system is created. Implementation details:
  • Calls base.OnCreate().
  • Retrieves the LoadGameSystem via base.World.GetOrCreateSystemManaged() and stores it in m_LoadGameSystem.
  • Builds an EntityQuery for ComponentType.ReadOnly() and stores it in m_EntityQuery.
  • Calls RequireForUpdate(m_EntityQuery) so the system only runs when there are Block entities.
  • Marked with [Preserve].

  • protected override void OnUpdate() : System.Void
    Called each frame/update when the system is allowed to run. Implementation details:

  • Checks if m_LoadGameSystem.context.purpose == Purpose.NewGame.
  • If true, adds the Updated component to all entities matched by m_EntityQuery via base.EntityManager.AddComponent(m_EntityQuery).
  • Marked with [Preserve].

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Get the load game system and query for Block components.
    m_LoadGameSystem = base.World.GetOrCreateSystemManaged<LoadGameSystem>();
    m_EntityQuery = GetEntityQuery(ComponentType.ReadOnly<Block>());
    RequireForUpdate(m_EntityQuery);
}

Notes: - The class depends on the presence of the Block and Updated component types, and on LoadGameSystem providing a context with a purpose property (enum Purpose). - [Preserve] attributes are used on the constructor and lifecycle methods to prevent them from being stripped by IL2CPP/optimizer.