Wayshaper Docs
View all packages

Reference

Scripting API

Build roads and rivers from code, read river flow, listen to rebuild events and add custom terrain stamps.

Wayshaper 26.12.0Unity 6000.0+URP · HDRP · Built-in

Everything is in the KiwiStudios.RiversRoads namespace.

Building paths from code

csharp
GameObject _object = new GameObject("Road");
RoadPath _road = _object.AddComponent<RoadPath>();
Spline _spline = _road.Container.Spline;
_spline.Add(new BezierKnot(new float3(0f, 0f, 0f)), TangentMode.AutoSmooth);
_spline.Add(new BezierKnot(new float3(60f, 0f, 20f)), TangentMode.AutoSmooth);
_road.Profile = roadProfile;
_road.Elevation = PathElevation.FollowTerrain;

//meshes first, then the terrain, which reads the finished paths
RoadNetwork.RebuildAll();
TerrainCompositor.FindOrCreate().RebuildAll();

The Runtime API sample builds rivers, roads and a junction this way.

Main types

TypeUse
RoadPathA road. Profile, Elevation, Frames, Length, FrameAtDistance, SetIntersection, Rebuild, Rebuilt event
RoadIntersectionA junction. Arms, Outline, TrimFor, SnapRoadEnds, Crosswalks, Rebuild
RoadNetworkRebuilds roads and intersections in the right order: Rebuild(road), Rebuild(intersection), RebuildAll()
RiverPathA river. Profile, ReverseFlow, FlowsInto, Frames, SurfaceHeightAt, TrySampleFlow, Rebuild
RiverFloaterFloats a Rigidbody on any river. Buoyancy, FlowGrip, FloatDepth, FloatPoints, InWater, LastSample
TerrainCompositorShapes terrains. Find, FindOrCreate, RebuildAll, Rebuild(bounds), RestoreOriginalTerrain, TrySampleOriginalHeight
RoadProfile, RiverProfileProfile assets. Every setting has a property; call NotifyChanged after changing one from a script
PathKnotDataPer-knot values: SetKnotValue(spline, PathKnotData.WidthKey, knot, value) with WidthKey, BankKey, DepthKey and SpeedKey
PathFrameA sample along a path: position, tangent, right, up, distance, widths, bank, depth, speed, curvature

Reading the flow

csharp
if (RiverPath.TrySampleAnyFlow(transform.position, out RiverFlowSample _flow) && _flow.InsideWater)
{
    body.AddForce(_flow.Velocity * grip, ForceMode.Acceleration);
    audioSource.volume = _flow.Turbulence;
}

RiverFlowSample holds the river, the surface point and normal, velocity and speed in metres per second, depth, distance from the source, lateral offset from the centre line, distance to the shore and turbulence from 0 for calm to 1 for white water.

Events

EventWhen
RoadPath.Rebuilt, RiverPath.Rebuilt, RoadIntersection.RebuiltAfter the mesh of that path is rebuilt
TerrainCompositor.BeforeTerrainWriteBefore the compositor writes to a TerrainData
TerrainCompositor.TerrainRebuiltAfter an area of a terrain is rebuilt, with the area in world space
TerrainCompositor.BaselineCapturedWhen the original of a terrain is first captured

Custom stamps

Implement ITerrainStampSource on a component and register it with TerrainCompositor.Register to stamp your own shapes, such as building pads, in the same pass as roads and rivers.

Still stuck?

Bring the scene with you.

Include the Wayshaper version, Unity and render-pipeline versions, the road or river profile involved, any inspector warnings, relevant logs, and a minimal scene with its Terrain Originals folder.

Email supportJoin Discord

Wayshaper 26.12.0

Search documentation