Skip to content

Game.Rendering.AggregateRenderSystem

Assembly: Assembly-CSharp.dll
Namespace: Game.Rendering

Type: class

Base: GameSystemBase

Summary:
AggregateRenderSystem hooks into Unity's ScriptableRenderContext rendering callback to draw aggregated overlay meshes produced by AggregateMeshSystem (name labels and "arrow" overlays). It queries other game systems (AggregateMeshSystem, RenderingSystem, ToolSystem) at creation, respects the RenderingSystem.hideOverlay flag, and selectively draws meshes only for game/editor cameras. The class is marked up for preservation to survive IL2CPP stripping.


Fields

  • private AggregateMeshSystem m_AggregateMeshSystem
    Holds a reference to the AggregateMeshSystem used to obtain aggregated meshes and materials for names and arrows. This is acquired via World.GetOrCreateSystemManaged in OnCreate.

  • private RenderingSystem m_RenderingSystem
    Reference to the RenderingSystem; used to check flags such as hideOverlay to avoid drawing overlays when they should be hidden.

  • private ToolSystem m_ToolSystem
    Reference to the ToolSystem; used to detect the active tool and whether it requires arrow rendering (activeTool.requireNetArrows).

Properties

  • None (this system exposes no public properties).

Constructors

  • public AggregateRenderSystem()
    Default constructor. No custom initialization is performed here; initialization occurs in the OnCreate override (typical pattern for managed game systems).

Methods

  • protected virtual OnCreate() : System.Void
    Called when the system is created. Implementation:
  • Calls base.OnCreate().
  • Acquires references to AggregateMeshSystem, RenderingSystem, and ToolSystem via base.World.GetOrCreateSystemManaged().
  • Subscribes the private Render method to RenderPipelineManager.beginContextRendering so the system can draw during the render pass.
  • Marked with [Preserve] to prevent IL2CPP stripping.

Modding tips: if you create your own system that depends on AggregateRenderSystem, ensure ordering or explicit retrieval to avoid null references.

  • protected virtual OnDestroy() : System.Void
    Called when the system is destroyed. Implementation:
  • Unsubscribes the Render method from RenderPipelineManager.beginContextRendering.
  • Calls base.OnDestroy().
  • Ensures the render callback is removed to prevent dangling callbacks after domain unload or mod unloading.

  • protected virtual OnUpdate() : System.Void
    Empty override in this implementation. No per-frame ECS update logic is executed here; rendering is handled in the render callback.

  • private void Render(ScriptableRenderContext context, List<Camera> cameras)
    Primary rendering callback invoked by Unity's SRP via RenderPipelineManager.beginContextRendering. Behavior:

  • Early-return if RenderingSystem.hideOverlay is true.
  • If ToolSystem.activeTool != null and activeTool.requireNetArrows is true:
    • Iterates arrow material sets from AggregateMeshSystem:
    • For each arrow mesh and submesh, gets the corresponding material and draws it using Graphics.DrawMesh for each camera of type CameraType.Game or CameraType.SceneView.
    • Returns after drawing arrows (arrow mode bypasses name drawing).
  • Otherwise:
    • Iterates name material sets from AggregateMeshSystem:
    • For each name mesh and submesh, gets the corresponding material and draws it for each Game/SceneView camera using Graphics.DrawMesh.
  • Drawing uses Matrix4x4.identity, layer 0, submesh index, null property block, and both castShadows and receiveShadows set to false.
  • The method wraps its body in a try/finally block with an empty finally; exceptions will still propagate (there is no catch).
  • Note: only Game and SceneView cameras are considered; other camera types are ignored.

Modding tips: - To draw your own aggregated overlays, populate AggregateMeshSystem with meshes/materials or extend it to provide custom sets. - Reuse the same camera filtering to match in-game overlay behavior. - Avoid long-running or allocation-heavy work in this callback — it's invoked during rendering. - If you need to change shadow behavior or layers, update the Graphics.DrawMesh call accordingly.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Acquire dependent systems and register render callback (same behavior as the original)
    m_AggregateMeshSystem = base.World.GetOrCreateSystemManaged<AggregateMeshSystem>();
    m_RenderingSystem = base.World.GetOrCreateSystemManaged<RenderingSystem>();
    m_ToolSystem = base.World.GetOrCreateSystemManaged<ToolSystem>();
    RenderPipelineManager.beginContextRendering += Render;
}

Additional note: The [Preserve] attributes are used to prevent IL2CPP/stripping tools from removing these methods. When modifying behavior, ensure you unsubscribe the render callback in OnDestroy to avoid callbacks after your mod or domain is unloaded.