Skip to content

Game.ModificationSystem

Assembly: Assembly-CSharp
Namespace: Game.Common

Type: class

Base: GameSystemBase

Summary:
ModificationSystem is a game system responsible for driving the "modification" phases of the game update pipeline. It holds a reference to the central UpdateSystem and, each frame, invokes UpdateSystem.Update for a sequence of SystemUpdatePhase values (Modification1, Modification2, Modification2B, Modification3, Modification4, Modification4B, Modification5, ModificationEnd). Methods and constructor are annotated with [Preserve] to avoid stripping by the runtime/IL2CPP, ensuring these lifecycle methods remain available at runtime for modded content.


Fields

  • private UpdateSystem m_UpdateSystem
    This field caches the UpdateSystem instance retrieved from the World. The ModificationSystem delegates work for modification phases to this UpdateSystem by calling its Update method with specific SystemUpdatePhase values.

Properties

  • None.
    This class does not expose any public properties.

Constructors

  • public ModificationSystem()
    Default constructor. Marked with [Preserve] to prevent the method from being stripped by linkers/IL2CPP.

Methods

  • protected override void OnCreate()
    Initializes the system. Calls base.OnCreate(), then retrieves (or creates) the UpdateSystem instance from the world and stores it in m_UpdateSystem:
  • m_UpdateSystem = base.World.GetOrCreateSystemManaged();

The [Preserve] attribute is applied to ensure this initialization runs even when aggressive code stripping is used.

  • protected override void OnUpdate()
    Main per-frame update entry. This method delegates a sequence of modification-phase updates to the cached UpdateSystem instance by calling m_UpdateSystem.Update(...) for each of these SystemUpdatePhase values in order:
  • Modification1
  • Modification2
  • Modification2B
  • Modification3
  • Modification4
  • Modification4B
  • Modification5
  • ModificationEnd

The ordering allows subsystems registered for those phases to run in the intended sequence. This method is also [Preserve] to avoid removal by code stripping.

Usage Example

using UnityEngine.Scripting;

namespace Game.Common
{
    public class ModificationSystem : GameSystemBase
    {
        private UpdateSystem m_UpdateSystem;

        [Preserve]
        protected override void OnCreate()
        {
            base.OnCreate();
            m_UpdateSystem = base.World.GetOrCreateSystemManaged<UpdateSystem>();
        }

        [Preserve]
        protected override void OnUpdate()
        {
            m_UpdateSystem.Update(SystemUpdatePhase.Modification1);
            m_UpdateSystem.Update(SystemUpdatePhase.Modification2);
            m_UpdateSystem.Update(SystemUpdatePhase.Modification2B);
            m_UpdateSystem.Update(SystemUpdatePhase.Modification3);
            m_UpdateSystem.Update(SystemUpdatePhase.Modification4);
            m_UpdateSystem.Update(SystemUpdatePhase.Modification4B);
            m_UpdateSystem.Update(SystemUpdatePhase.Modification5);
            m_UpdateSystem.Update(SystemUpdatePhase.ModificationEnd);
        }

        [Preserve]
        public ModificationSystem()
        {
        }
    }
}

Additional notes: - The UpdateSystem is expected to host and run other systems or callbacks associated with each SystemUpdatePhase. If you are creating a modded system that should run during one of these modification phases, register it with UpdateSystem (or implement the appropriate registration mechanism used by the game's UpdateSystem) so it will be executed when ModificationSystem triggers the corresponding phase. - The [Preserve] attribute is commonly used in Cities: Skylines 2 modding to ensure methods survive binary stripping in release builds (IL2CPP/AOT).