Skip to content

Game.Tools.ObjectToolBaseSystem

Assembly: Assembly-CSharp
Namespace: Game.Tools

Type: abstract class

Base: ToolBaseSystem

Summary:
ObjectToolBaseSystem is an abstract ECS system used by the in-game object placement tool (brush/paint/placer) in Cities: Skylines 2. It coordinates placement logic by scheduling a Burst-compiled CreateDefinitionsJob that inspects control points, evaluates brush/curve placement, samples terrain/water, handles editor/upgrade/relocate flows, and emits CreationDefinition/ObjectDefinition/NetCourse/Area entities into a ToolOutputBarrier command buffer. The system also wraps access to related runtime systems (ToolOutputBarrier, SearchSystem, WaterSystem, TerrainSystem) and provides helpers such as GetFirstNodeIndex used by area/sub-area placement logic.

This class contains several nested types: - AttachmentData: small POD struct used to pass an entity + offset for attachments. - CreateDefinitionsJob: heavy Burst IJob implementing the placement algorithm. It contains many helper methods (CreateCurve, CreateBrushes, UpdateObject, UpdateSubNets, UpdateSubAreas, SampleTransform, etc.) which perform the bulk of object creation logic. - TypeHandle: internal container of ComponentLookup / BufferLookup handles used to bind data to the job.


Fields

  • protected ToolOutputBarrier m_ToolOutputBarrier
    Used to create command buffers for producing creation/update entities for the main simulation to consume. The job created by CreateDefinitions uses a command buffer from this barrier.

  • protected Game.Objects.SearchSystem m_ObjectSearchSystem
    Reference to the game's static object search system used for searching existing objects in the world (used primarily by the brush erase logic).

  • protected WaterSystem m_WaterSystem
    Reference to water surface data provider; used when sampling water heights/conditions for placement.

  • protected TerrainSystem m_TerrainSystem
    Reference to terrain height data provider; used for sampling terrain height and normals.

  • private TypeHandle __TypeHandle
    Internal struct holding component lookups / buffer lookups that are bound into the CreateDefinitionsJob.

Properties

  • None (no public properties exposed by this class)

Constructors

  • protected ObjectToolBaseSystem()
    Default protected constructor. The system is intended to be subclassed; the runtime constructs derived tool systems.

Methods

  • [Preserve] protected override void OnCreate()
    Initializes references to dependent systems: ToolOutputBarrier, Game.Objects.SearchSystem, WaterSystem and TerrainSystem. Called by the ECS lifecycle; override preserves base behavior.

  • protected JobHandle CreateDefinitions(Entity objectPrefab, Entity transformPrefab, Entity brushPrefab, Entity owner, Entity original, Entity laneEditor, Entity theme, NativeList<ControlPoint> controlPoints, NativeReference<AttachmentData> attachmentPrefab, bool editorMode, bool lefthandTraffic, bool removing, bool stamping, float brushSize, float brushAngle, float brushStrength, float distance, float deltaTime, RandomSeed randomSeed, Snap snap, AgeMask ageMask, JobHandle inputDeps)
    Schedules the Burst-compiled CreateDefinitionsJob which performs all placement logic based on the provided parameters and control points. The method wires up many ComponentLookup/BufferLookup handles and runtime data sources (object search tree, water/terrain data), schedules the job, and registers it as a reader/producer with the respective systems (object search, water, terrain, tool output barrier). Returns the JobHandle representing the scheduled job.

  • protected override void OnCreateForCompiler()
    Internal override used at compile-time wiring to assign queries and type handles. Calls __AssignQueries and TypeHandle.__AssignHandles.

  • public static int GetFirstNodeIndex(DynamicBuffer<SubAreaNode> nodes, int2 range)
    Utility used by area placement to determine a "first" node index for polygon/orientation calculations; returns the index within the node buffer that is closest to an origin (implementation scans edges and chooses the best candidate).

  • private void __AssignQueries(ref SystemState state)
    Internal helper used to assign ECS queries (empty in this class but invoked for compiler-generated wiring).

  • (Nested) CreateDefinitionsJob.Execute() and helpers
    The nested Burst job implements:

  • Execute(): main entry that reads the first control point and iterates placement logic.
  • CreateCurve(), CreateBrushes(): creates objects along a curve or within a brush (paint) area.
  • SampleTransform(): samples terrain/water to compute a transform and elevation for a placement.
  • UpdateObject(): creates a CreationDefinition + ObjectDefinition or expands subobjects/subnets/subareas, handling attaching/upgrading/relocating/rebuilding cases.
  • UpdateSubNets(), UpdateSubAreas(), UpdateSubObjects(), CreateSubNet(): handle creation of nets, areas, and nested subobjects and their various placement constraints.
  • CheckParentPrefab(), IsLoweredParent(), UpdateAttachedParent(): utility checks for parent/attachment rules and alignment behavior.
  • GetVariationData(), GetOwnerLot(): miscellaneous helpers used for placeholder/variation and lot calculations.

The job reads and writes many component buffers/lookups and uses a command buffer to emit creation/update commands.

Usage Example

// Example override: initialize referenced systems in your derived tool system.
[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // ObjectToolBaseSystem.OnCreate already retrieves:
    // m_ToolOutputBarrier, m_ObjectSearchSystem, m_WaterSystem, m_TerrainSystem
}

// Example: schedule placement definitions (typical call-site inside a tool update loop)
JobHandle deps = default;
NativeList<ControlPoint> controlPoints = new NativeList<ControlPoint>(Allocator.Temp);
// populate controlPoints...
NativeReference<ObjectToolBaseSystem.AttachmentData> attachment = new NativeReference<ObjectToolBaseSystem.AttachmentData>(Allocator.Temp);
JobHandle job = CreateDefinitions(
    objectPrefab: someObjectPrefab,
    transformPrefab: someTransformPrefab,
    brushPrefab: someBrushPrefab,
    owner: someOwner,
    original: someOriginal,
    laneEditor: someLaneEditor,
    theme: someTheme,
    controlPoints: controlPoints,
    attachmentPrefab: attachment,
    editorMode: false,
    lefthandTraffic: false,
    removing: false,
    stamping: false,
    brushSize: 5f,
    brushAngle: 0f,
    brushStrength: 1f,
    distance: 0.0f,
    deltaTime: Time.deltaTime,
    randomSeed: new RandomSeed(12345),
    snap: Snap.None,
    ageMask: AgeMask.Default,
    inputDeps: deps
);
// Remember to complete / combine job handles as needed and dispose temporary containers.

Notes and tips: - The CreateDefinitionsJob is Burst-compiled and reads many component/buffer lookups — ensure that any mod changes that affect those component types remain compatible. - Brush erase logic uses the object search tree and can create Delete CreationDefinitions; brush placement respects prefab placeholder/variation and spawnable probabilities. - When extending or subclassing tools, call base.OnCreate() to ensure the system retrieves the required runtime systems.