Skip to content

PCG basics

Have an agent scatter meshes across a landscape with Unreal's Procedural Content Generation framework, read back how many instances it placed, then edit the graph node by node.

Before you start

Prompt

Prompt
Scatter /Engine/BasicShapes/Cone across the landscape at 0.05 points per square metre, with random yaw and scale between 0.8 and 1.4. Tell me how many instances were placed. Then list the generated graph's nodes, lower the density to 0.02, regenerate, and give me the new count.

What the agent does

  1. pcg_scatter_mesh builds a jittered PCG graph, places a PCG volume bound to it, generates, and returns the instance count. It fails loudly on zero instances.
  2. hayba_export_pcg_graph returns the graph as JSON: its nodes, settings and edges.
  3. pcg_set_prop changes the sampler's density. Nested settings use / paths.
  4. pcg_cook_and_wait regenerates the volume, waits for the graph to settle and returns the instance count per mesh.

Trust the counts from pcg_cook_and_wait. PCG generates asynchronously, so a plain generate reads zero in the same call, and pcg_read_node_output reads a cache that may be stale.

Editing the graph

To build or change a graph by hand rather than with the one-call scatter:

  1. hayba_search_node_catalog finds a node by what it does, when the class name is not known.
  2. pcg_add_node adds a node by its settings class. New nodes land at the origin of the graph.
  3. pcg_list_pins lists a node's exact pin labels. Labels are not obvious: the graph input's output pin is In.
  4. pcg_wire connects two pins. It checks the pin names first and never drops a wire silently.
  5. pcg_layout arranges the nodes left to right. Close and reopen the graph editor tab to see the new positions.
  6. pcg_get_node reads one node's settings in full, and hayba_introspect lists the properties of a settings class.

To remove things, pcg_disconnect cuts one edge and pcg_remove_node deletes a node and its edges. Node indices shift after a removal, so the agent re-reads the graph before the next edit.

Check the result