PCG spline from landscape material border

Hello guys. Any idea how to make a spline follow the border between 2 landscape materials ? Tried a few things but no luck so far. Would be cool to help make automatic fences or walls .

Automatically generating a spline that perfectly follows the sharp border between two Landscape Materials isn’t directly supported out of the box, but there are several good approaches depending on how precise and automatic you want it to be.1. Best & Recommended Approach: Landscape Splines + Manual/A semi-auto Placement

  • Use Landscape Splines (in Landscape mode → Splines). They are specifically designed for this kind of thing (roads, fences, walls) and will conform to the landscape surface.

  • You can attach fence/wall meshes directly to the spline segments.

  • For borders: Place the spline roughly along the transition area. You can then use the spline to also paint a Landscape Layer (e.g., a transition or path layer) to clean up the material blend if needed.

This is the most common and performant way for fences/walls.2. More Automated Solutions

  • PCG (Procedural Content Generation):
    Sample the landscape layers or Physical Materials along a grid or existing spline, then filter points where the weight of one material vs. the other is around 0.5 (the transition zone). From those points you can generate a new spline or directly spawn fence meshes.
    This is probably the closest to true “automatic border following.”

  • Blueprint/Python Script:
    Write a small editor utility that:

    1. Samples many points across the landscape.

    2. Uses Get Landscape Material at Location (via trace + Physical Material or Landscape Layer Sample logic).

    3. Detects transitions (where material A meets material B).

    4. Generates spline points along those edges.

  • Manual Painting + Spline: Paint a thin “fence layer” or “border” layer where the two materials meet, then use that painted area as a guide for spline placement or PCG spawning.

Quick Tips

  • Assign different Physical Materials to your landscape layers. This makes it much easier to detect transitions at runtime or in PCG.

  • For fences/walls, Landscape Splines have built-in support for meshes with random variation, up-vector alignment, etc.

Thank you for your detailed answer.

Solution 2, PCG, Is what I tried before but as the points aren’t ordered, the create spline node makes a mess. How would I fix that ?

Yes, that’s the classic problem with PCG + borders — the points are generated in random order, so Create Spline connects them in the wrong sequence and creates a huge mess.Best Ways to Fix Point Ordering in PCG:1. Best & Cleanest Method (Recommended)Use PCG + Trace + Sorting to create an ordered chain:

  • After sampling the transition points (where the two landscape layers meet), use a PCG Point Filter or Density Filter to get clean border points.

  • Add a PCG Create Spline node, but feed the points through a Custom PCG Graph or Blueprint that does proper ordering:

    • Use the “Sort Points Along Spline / Direction” technique.

    • One reliable way is to:

      1. Find the point with the lowest X (or Y) value as the starting point.

      2. Then iteratively find the nearest neighbor to the last point and add it to a new ordered array.

      3. Finally create the spline from the ordered points.

This “nearest neighbor chaining” is the most common solution for border splines.2. Simpler Alternative (Good Enough for Many Cases)

  • Use Landscape Splines instead of regular Spline Actors.

  • Or generate the points with PCG, then use the “Project Points to Spline” or convert them into a Spline Mesh chain with a PCG Spawn Actor node that places small spline segments.

3. Even Better Approach (Hybrid)Many people combine both:

  1. Use PCG to detect and spawn points only on the material border.

  2. Use a small Editor Utility Blueprint or Python script to turn those points into a clean ordered spline (much easier to sort in Blueprint/Python).