← Back to list

PCG: Presets and Loops

How to use Data Assets with Subgraph loops

Iri Shinsoj · 2025-11-24 19:43 · 31 claps · 3.9 min read
#unreal-engine
Open on Medium ↗
Wiki topics: 🎮 · Gaming

PCG: Presets and Loops

How to use Data Assets with Subgraph loops

A very simple setup example to show how to use loops and Data Assets. Written a year ago but posted only now, as I barely have any free time for my blog recently. Engine version used: 5.4. This setup won’t work on earlier versions.

The most basic and common asset spawner usually looks something like that:

basic spawner subgraph

basic spawner subgraph

It uses an array of Stucts as a parameter, which contain a mesh and it’s weight:

This is a pretty simple graph with “hardcoded” generation rule. But, if I want to have multiple archetypes of assets, I’d have to have a bunch of separate subgraphs in a row. And I’d have to manually set generation and spawner rules for each.

To make it more universal, it should make use of loops. On top of that, I want to have an ability to save presets for biomes that can be reused, and make it easy to swap from one to another without any additional manual work. Here is the idea of hierarchy:

Data Assets with Structs

DA_Biome

I created a Data Asset to use for biome presets which utilizes a Struct, that has all the parameters I want to be able to customize per type of an asset.

Order of the elements in the array is used as priority, so that the next points will be discarded where some other points have already been spawned previously (eg. put trees first, then saplings, then grass).

DA_MeshSelector

Mesh Selector is a Data Asset with array of Structs that contain mesh and weight:

This is basically archetypes of assets you want to spawn.

Containers of Meshes

Containers of Meshes

DA_MeshSelectorParameters

Mesh Selector Parameters is another Data Asset with a Struct that contains universal set of parameters per type of assets, like shadow casting and culling distances:

an example of Mesh Selector Parameters

an example of Mesh Selector Parameters

Subgraph loops

First we loop through biomes stored in DA_Biome:

Main Graph

Main Graph

Then we loop through each layer inside of each biome:

UnpackBiomes subgraph

UnpackBiomes subgraph

PCG_Unpack_Biomes

In Get Property From Object Path we use Biome attribute as an input source, which stores an array of DA_Biome presets with all the parameters:

attribute storing the DA_Biome preset

attribute storing the DA_Biome preset

DA_Biome parameter storing an array of assets containers

DA_Biome parameter storing an array of assets containers

PCG_Unpack_Biome_Layers

Here I’m creating points using the generation rules from the unpacked **DA_Biome** layers:

Delete Attributes nodes are used to isolate particular parameter for each input. After setting up the Sampler and Transform, I’m projecting the points onto the landscape surface. Select node ensures that trees keep absolute rotation after projection, otherwise they would align to the terrain slopes.

After that, I’m discarding all unnecessary points using landscape layers and previously spawned points, as well as checking self clipping.

Then, I’m unpacking an array of meshes from the DA_MeshSelector and unpacking DA_MeshSelectorParameters to override parameters in the Static Mesh Spawner:

Static Mesh Spawner is a bit tricky here, you need to bind each parameter from your input (Mesh Selector Parameters):

And the last section is for selecting which bounds to use for culling of the next points (for example, for rocks I’d want to use mesh bounds to cull out the meshes precisely following the mesh size, while for trees, I’d want to use point bounds to cover only the trunk width):

And the PCG actor itself has parameters for Landscape layer and Biome to use on it:

That’s it, that’s a basic loop setup with Data Assets, that you can expand with extra rules and customization.

Here’s a draft I did in couple hours using this PCG actor:


메타데이터
post_id
dae144397e6f
slug
pcg-presets-and-loops-dae144397e6f
url
https://medium.com/@shinsoj/pcg-presets-and-loops-dae144397e6f
canonical_url
https://medium.com/@shinsoj/pcg-presets-and-loops-dae144397e6f
author_url
https://medium.com/@shinsoj
status
ok
fetched_at
2026-06-15 22:55:51