Unit

Create Workers 1: Worker Units and Creation Workflow

Learn how to create worker units, validate resources and spawn locations, set ownership and idle state, and verify successful production.

A worker is a unit created for economic, construction, maintenance, transport, or other utility tasks. Workers are usually non-combat units: instead of attacking enemies, they gather resources, build structures, repair damaged objects, transport items, or perform another assigned job.

A unit is an individual entity controlled by a player, faction, or system. Combat units are designed primarily for fighting, while workers are designed primarily for supporting the economy and the game world. Some games allow a worker to defend itself, but its main purpose remains utility work.

What a Worker Does

  • Gathering: Collecting resources from a mine, forest, field, or other resource source.
  • Building: Constructing a structure after receiving a construction order.
  • Repairing: Restoring health or durability to a structure, vehicle, or other unit.
  • Transporting: Carrying resources or objects between locations.
  • Assigned tasks: Performing a job selected by the player or chosen by an automated system.

This lesson focuses on creating the worker. Assigning a worker to gathering, construction, or another task comes later. The creation step should therefore produce a valid worker that is ready for assignment.

Worker Creation Workflow

Production is the process of creating a new unit. A player normally starts production from a worker-producing structure, such as a base, town center, factory, or similar production source. In another design, a central game system may create the worker directly on behalf of the player.

  1. The player selects the appropriate production source or opens its production menu.
  2. The player chooses the worker action, such as Create Worker or Train Worker.
  3. The system checks the request's preconditions, including ownership, resources, capacity, prerequisites, and placement.
  4. If the request is approved, the system reserves or deducts the required resources and either creates the worker immediately or adds it to a production queue.
  5. When production completes, the worker is spawned. Spawning means placing the newly created unit into the active game or simulation state.
  6. The system assigns the worker an owner, a valid position, default properties, and an initial state such as idle or ready for assignment.

A queue is an ordered list of units or actions waiting to be produced or processed. If production is immediate, the worker can spawn during the request. If production takes time, the request creates a queue entry first and the worker spawns when that entry completes.

Example: Creating One Worker

  1. A player requests a worker from the appropriate production source.
  2. The system checks whether the player can afford the resource cost and whether the source can produce another unit.
  3. The system selects a valid spawn location near the production source.
  4. The worker is added to the active unit registry with the requesting player as its owner.
  5. The worker begins in an idle or ready-for-assignment state.

Worker Default Properties

Every newly created worker needs enough data to be identified, controlled, placed, and assigned a task. Exact property names differ between games and simulations, but the following minimum data is broadly useful.

PropertyPurposeExample Initial Value

Identity — Uniquely identifies the unit — worker-1042

Unit type — Indicates the unit's class and capabilities — worker

Owner — Identifies the player or faction that controls the unit — playerA

Position — Stores the worker's location in the game world — A valid tile beside the production source

State — Describes the worker's current activity — idle

Task — Holds the current assignment, if any — null or none

Capabilities — Lists actions the worker can perform — gather, build, repair

Health or durability — Provides a usable starting condition — The worker's configured maximum value

Availability — Indicates whether the worker can receive a new order — ready

Default values should be deliberate. For example, a newly spawned worker should normally have no active task, a valid owner, a valid position, and a state that allows later task assignment. A missing owner or an unregistered worker may appear on screen but remain uncontrollable.

Creation Preconditions and Constraints

A creation precondition is a requirement that must be true before production can succeed. Common constraints include resource cost, production capacity, queue capacity, cooldowns, prerequisites, and a valid spawn location.

PreconditionWhy It Is RequiredResult When It Fails

Valid requesting player — The system must know who receives control — Reject the request

Required resources — Production may consume food, minerals, energy, or another resource — Return an insufficient-resources result; create nothing

Available production source — A source may be destroyed, disabled, or owned by another player — Reject the request

Capacity or unit limit — The game may limit active units or source capacity — Reject or defer the request

Queue availability — A full queue cannot accept another production item — Reject or ask the player to wait

Prerequisites — A technology, structure, or progression level may be required — Reject the request

Valid spawn location — The worker needs a usable, unblocked position — Reject, defer, or choose a valid fallback location

Cooldown complete — Some sources must wait between production actions — Reject or defer until the cooldown ends

State Changes During Successful Creation

When the request is approved, update state in a consistent order. Reserve or deduct the resource cost only after validation succeeds. Then create the worker, assign its identity and owner, place it, register it in the active unit collection, and set its initial state. Finally, update the production source, queue, capacity count, and any user interface status.

request worker
  validate player, source, prerequisites, capacity, and spawn location
  if validation fails:
    return failure
  reserve or deduct resource cost
  create worker with a unique identity
  assign owner and default properties
  place worker at a valid spawn location
  add worker to the active unit registry
  set state to idle and task to none
  update production state
  return success

If validation fails, the existing game state should remain unchanged. In particular, do not deduct resources when no worker will be created. This prevents a failed request from unfairly reducing the player's resources.

Initial Worker State

The idle state means that no active task has been assigned to the worker. A newly spawned worker may also be described as spawned, selected, queued, or awaiting assignment, depending on the system's state model.

  • Spawned: The worker has been placed in the active world.
  • Idle: The worker is present but has no current task.
  • Ready: The worker can receive a command immediately.
  • Selected: The user interface has selected the worker. Selection is optional and should not be confused with ownership.
  • Queued: The production request is waiting and the worker does not yet exist as an active unit.

A useful initial combination is state = idle, task = none, and availability = ready. The worker should not begin gathering or building automatically unless that behavior is explicitly part of the design. Starting idle makes the next task-assignment lesson predictable.

Preventing Duplicate Creation

Each accepted request should create exactly one worker. A common error is allowing the same button event, network message, or update cycle to be processed twice. Use a single authoritative production path and give each request a clear result, such as success, queued, or rejected.

  • Validate the request once in the authoritative game or simulation state.
  • Deduct or reserve resources once, after validation.
  • Create one unique unit for one approved immediate-production request.
  • For queued production, create the unit only when its queue entry completes.
  • Register the new unit once in the active unit collection.

Verification Checklist

After creating a worker, verify all of the following:

  1. Exactly once: One approved request results in one worker, not zero or multiple workers.
  2. Ownership: The worker's owner and controller references point to the requesting player or faction.
  3. Placement: The worker is inside the valid play area, occupies an available location, and is not stuck inside another object.
  4. Registration: The worker is present in the active unit list or entity registry used by selection and control systems.
  5. Initial state: The worker is idle or otherwise ready for assignment, with no accidental task.
  6. Capabilities: The worker has the task-related abilities expected by later lessons.
  7. Resources: The appropriate cost was deducted exactly once after approval.
  8. Capacity: The player's unit count and production source's capacity were updated correctly.

Practical Constraint Examples

Insufficient Resources

The player requests a worker, but the player's available resources are below the resource cost. The cost check fails, no worker is created, and the existing unit list and resources remain unchanged except for any explicit failure notification. The result should clearly indicate that resources are insufficient.

Creating Multiple Workers

When several requests are made, evaluate each request independently or add each approved request to the production queue. Capacity, resource availability, cooldowns, and spawn locations determine the result of each request. Do not assume that approving the first request automatically approves every later request.

Blocked Spawn Location

If the normal location beside the production source is occupied, search for a valid nearby location according to the placement rules. If no valid location exists, reject or defer creation cleanly rather than spawning the worker outside the map or inside another unit.

Troubleshooting

A Worker Creation Request Produces No Unit

  • Check whether the requesting player has the required resources.
  • Check whether the production source is available and owned correctly.
  • Check capacity, queue length, cooldown, and technology or structure prerequisites.
  • Verify that the creation action is connected to the production and spawn logic.
  • Verify that resources are deducted only after approval, and that a successful request creates and registers the worker.

A Worker Appears but Cannot Be Controlled

  • Verify the worker's owner and controller references.
  • Verify that the worker was added to the active unit list or entity registry.
  • Verify that the worker has a valid initial state such as idle or ready.
  • Verify that task capabilities were initialized and that no invalid task reference blocks commands.

Workers Spawn in an Invalid Location

  • Check that spawn coordinates are defined and use the correct coordinate system.
  • Check whether the selected location is blocked or outside the valid area.
  • Check occupancy before placement, especially when multiple workers are created quickly.
  • Provide a fallback location or reject the request cleanly when no location is available.

Key Takeaways

  • A worker is a utility-focused unit used for gathering, building, repairing, transporting, or similar tasks.
  • A production source or system receives the creation request and validates its preconditions.
  • A successful worker needs a unique identity, owner, valid position, state, task data, and capabilities.
  • Resource cost, capacity, queues, cooldowns, prerequisites, and spawn availability can limit production.
  • A newly spawned worker should normally be idle and ready for later task assignment.
  • Verification must confirm one creation per approved request, correct ownership and placement, active registration, and readiness for control.