Any City Generator · Documentation

Editing, JSON and Scripting

A road network is its layout: the nodes, the roads between them and each road's profile. Meshes, lanes and city blocks are rebuilt from it. This article covers editing a layout by hand, joining networks, the generator tab's other buttons, layout files in JSON, scripting with Python, and the lane, route and block queries your game can use.

← All Any City Generator documentation

1 · The viewport

Drag points, then right-click for the rest

Select a network. Its nodes (amber) and control points (cyan) near the camera appear, with each road's curve drawn through them. Click a point and drag the gizmo; the network rebuilds when you release it.

▾ Right-click on a road or point

Add Point Here On a road's curve: inserts a control point there. The road keeps its shape until you move the point
Delete Point On a control point: removes it, and the road is rebuilt through the remaining points
Split Road Here On a control point: it becomes a node where two roads with the same profile meet
Delete Node (Join Roads) On a node where exactly two roads meet: joins them into one road, keeping the longer road's profile and direction. Not for ports
Reset Tangent On a node or tangent handle: the road's direction through the node comes from the neighbouring points again

Points farther than Edit Point Draw Distance (60 m, under Project Settings > Plugins > Any City Generator > Road Editing) stay hidden, so fly close to the junction you want to edit. Alt-drag a control point to drag out a copy. A selected node where one or two roads meet shows tangent handles: drag one to turn the road through the node without moving it. Each move or menu action is one undo step.

Delete doesn't remove the network while you edit points. It deletes the selected point or node, or resets a selected tangent handle. To delete the whole network, click its road mesh first.

2 · The Details panel

Exact values in Network > Layout

The viewport shows no labels. For ids and exact values, select the network and open Details > Network > Layout. Every edit there rebuilds the preview.

▾ Network > Layout

Driving Side Right or Left, for the whole network
Nodes Location (relative to the actor), Junction Type, Control, Corner Radius, roundabout size and lanes, signal timing and Is Port
Segments Start Node Id and End Node Id, Profile, End Profile for a transition, Control Points and Structure (Auto, Ground or Bridge)
+ or Insert Adds a default element with a fresh id: a node at the actor's origin, or a segment that needs its two node ids before it builds
Duplicate Copies an element. The copy gets a fresh id and the original keeps its own

Build Editor Preview Now under Details > Network builds at once; Rebuild Network builds on the next editor tick. Scale a network actor evenly, if at all: lane widths stay in profile units.

3 · Ports

Join two networks at their ports

A port is a node with Is Port and exactly one road: an open end another network can join. Traffic and routes cross once two ports meet within 100 cm and face each other, which is hard to hit by dragging. Bring the ports within Port Connect Distance (30 m), select the network that should move, then right-click its port node:

▾ Right-click on a port node

Connect To Nearest Port This port moves onto the nearest port of another network and its road turns to face it. Only this network's road bends
Move Network To Nearest Port This whole network turns (yaw only) and moves so its port meets the other. The roads keep their shape
Add Transition To Nearest Port This port's road changes to the other port's profile over a transition, so every lane continues across

The other network never changes, and each entry is one undo step. Draw Ports (Details > Debug, on by default) shows an arrow at every port once the network has rebuilt: orange is open, green means every lane continues across, yellow only some, magenta none (usually two different profiles).

4 · The generator tab

Spawn, rebuild, export and import

Tools > Any City Generator > Any City Generator has more buttons than Generate City:

▾ Any City Generator

Generate Block Generate City with Size set to Block: a single block
Spawn Traffic Manager Unless the level has one, spawns the traffic manager at the world origin as AnyTrafficManager
Rebuild All Networks Builds every network in the level now
Export Selected Layout... Writes the selected network's layout to a JSON file
Import Layout Into Selected... Replaces the selected network's layout from a JSON file and builds it, as one undo step. A file with any problem changes nothing

Import keeps the network's position and rotation, because layout locations are relative to the actor. The tab's status line shows the last result; when something fails, the reason is in the Output Log under LogAxCity (generation) or LogAxRoad (builds and files).

5 · JSON

Layouts as JSON files

A layout file holds one network's nodes, segments and road profiles. Locations, radii and widths are in centimetres, relative to the network actor; signal times are in seconds. Every file names its format: "AnyCityLayout", version 1.

▾ Top-level fields

format, version Exactly "AnyCityLayout" and 1. Required
drivingSide Right (the default) or Left
profiles A name of your choice for each road profile, mapped to its asset path. Required when there are segments
nodes id and location [x, y, z]; optional tangent, junction, control, port, cornerRadius, roundabout values and signal timing
segments id, start and end node ids, and a profile name; optional endProfile, controlPoints and structure

{
  "format": "AnyCityLayout",
  "version": 1,
  "drivingSide": "Right",
  "profiles": { "local": "/AnyCityGenerator/Data/AnyRoad/Profiles/DA_Road_Local" },
  "nodes": [
    { "id": 1, "location": [0, 0, 0], "port": true },
    { "id": 2, "location": [6000, 0, 0] }
  ],
  "segments": [
    { "id": 1, "start": 1, "end": 2, "profile": "local", "controlPoints": [[3000, 1500, 0]] }
  ]
}

This is a curved local street with a port at node 1 and a turnaround bulb at node 2. Names such as Roundabout or TrafficSignal are not case-sensitive. Export writes every field, defaults included, and import keeps the ids. A file with a problem (wrong format or version, a missing field, an unknown name or profile) is logged to LogAxRoad, and the editor import then applies nothing.

Some problems only show in the build. A duplicate id, a missing node or a profile without a Driving lane still imports; the build logs each one and the network stays unbuilt.

6 · Scripting

Drive the plugin from Python or an AI agent

Every button except New Seed calls an editor library, so a script does what the tab does, with the same undo steps. Run Python from the editor console in Python mode, or as py "<file>.py" in Cmd mode. An AI agent connected to the editor through an MCP server that runs Python can call the same functions.

▾ unreal.AxCityEditorLibrary

generate_city_in_editor(request) Generate City without the tab. Spawns no traffic manager. Returns the network, or None on failure
spawn_traffic_manager_in_editor() Spawns a manager when the level has none. Returns the new or existing one
rebuild_all_road_networks() Builds every network. Returns how many are built
export_network_layout_to_file(network, path) Writes the layout as JSON, overwriting the file. True when written
import_network_layout_from_file(network, path) Applies the file in one undo step, then builds. On False nothing changed
get_selected_road_network() The most recently selected network, or None

import unreal

editor_library = unreal.AxCityEditorLibrary

# A small town 200 m along X, built before the call returns.
request = unreal.AxCityGenerationRequest()
request.preset = unreal.load_asset("/AnyCityGenerator/Data/AnyCity/Presets/DA_City_Town")
request.size = unreal.AxCitySize.SMALL
request.seed = 4711
request.origin = unreal.Vector(20000.0, 0.0, 0.0)

network = editor_library.generate_city_in_editor(request)

if network is None:
    raise RuntimeError("Generation failed; see LogAxCity.")

# Blocks are relative to the network actor.
for block in network.get_blocks():
    block_center = network.get_actor_transform().transform_location(block.centroid)
    unreal.log("Block of {:.0f} m2 at {}".format(block.area / 10000.0, block_center))

# Export the layout to the project's Saved folder.
saved_dir = unreal.Paths.convert_relative_path_to_full(unreal.Paths.project_saved_dir())
editor_library.export_network_layout_to_file(network, saved_dir + "AnyCity_4711.json")

Editor calls build before they return, so a script can read blocks, lanes and ports straight away. Pass absolute file paths. Editor Utility Blueprints find the same functions under City Editor. unreal.AxOsmEditorLibrary runs the OpenStreetMap import the same way, and unreal.AxRoadLayoutJsonLibrary converts a layout to and from JSON text.

In a packaged game the editor library isn't there, but generation and import are runtime code. Spawn City Network builds a generated city, Generate City Layout returns the layout and its messages without spawning anything, and Import Osm File with Spawn Osm Networks builds an OpenStreetMap town. Each spawned network builds itself in BeginPlay.

7 · Lanes and routes

Lane and route queries for a GPS line or your own drivers

Every network builds a lane graph: each drivable path as a line of points, junctions included, linked to the lanes traffic continues into. The road network subsystem joins the lanes of all networks at their ports and answers these queries in the game, in Play In Editor and in the editor level. In Blueprint, get the subsystem with its getter node.

▾ Road network subsystem

Find Nearest Lane The lane closest to a world location within Max Distance (1000 cm by default): the lane, the distance along it, the side offset and the travel direction. Invalid when no lane is in range
Find Route The lanes from a start lane to a goal lane, both included: the fastest by speed limits, not by current traffic. Empty when unreachable
Get Lane Location At Distance A world point along a lane
Get Lane Transform At Distance A transform along a lane, with X pointing the way traffic travels
Get Lane Length The lane's length in cm

#include "Subsystems/AxRoadNetworkSubsystem.h"

// A point every 10 m along the route from the player to a destination.
TArray<FVector> AMyPlayerController::BuildRoutePoints(FVector InDestination)
{
    TArray<FVector> RoutePoints;

    UAxRoadNetworkSubsystem* RoadSubsystem = GetWorld()->GetSubsystem<UAxRoadNetworkSubsystem>();

    FAxLaneLocation StartLocation = RoadSubsystem->FindNearestLane(GetPawn()->GetActorLocation(), 1500.f, true);

    FAxLaneLocation GoalLocation = RoadSubsystem->FindNearestLane(InDestination, 1500.f, true);

    TArray<FAxLaneHandle> Route = RoadSubsystem->FindRoute(StartLocation.Lane, GoalLocation.Lane);

    for (FAxLaneHandle& RouteLane : Route)
    {
        float LaneLength = RoadSubsystem->GetLaneLength(RouteLane);

        for (float Distance = 0.f; Distance < LaneLength; Distance += 1000.f)
        {
            RoutePoints.Add(RoadSubsystem->GetLaneLocationAtDistance(RouteLane, Distance));
        }
    }

    return RoutePoints;
}

Your game module needs AxRoad in its dependencies to call this from C++. The nearest lane may run the other way, so compare its Direction with the heading you want. Distances are measured in 3D, so a bridge and the street under it are told apart. To start exactly at the player and stop at the destination, cut the first and last lanes at the two Distance values.

Find the route again when the roads change. A rebuilt network invalidates its lane handles: listen to On Road Network Changed on the subsystem and rebuild the route.

8 · City blocks

City blocks for placing buildings

Generators leave the space between streets empty. Once a network is built (Is Network Built), Get Blocks on the network returns those spaces, already inset to the outer edge of the sidewalks and around curb corners and dead-end bulbs.

▾ Each block

Outline The block's edge as points at Z 0, counter-clockwise seen from above
Area In cm²: divide by 10 000 for m²
Centroid The centre of the outline's area
Bounding Segment Ids The ids of the roads around the block

Outline and Centroid are relative to the network actor: transform them with the actor's transform before you spawn anything, as the Python example above does. Highway, Ramp and (by default) elevated roads pass over blocks instead of bounding them, and blocks smaller than Min Block Area (40 m², under Details > Blocks) are dropped. Draw Blocks under Details > Debug draws every outline. An OpenStreetMap import brings no buildings, but Get Blocks still returns the spaces between its streets.

That's the whole system. Stuck, or after a road layout we haven't shown? Send us a message or an image of the city you want, and we'll help you build it.