Reference
Scripting API
Build roads and rivers from code, read river flow, listen to rebuild events and add custom terrain stamps.
Everything is in the KiwiStudios.RiversRoads namespace.
Building paths from code
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
| Type | Use |
|---|---|
RoadPath | A road. Profile, Elevation, Frames, Length, FrameAtDistance, SetIntersection, Rebuild, Rebuilt event |
RoadIntersection | A junction. Arms, Outline, TrimFor, SnapRoadEnds, Crosswalks, Rebuild |
RoadNetwork | Rebuilds roads and intersections in the right order: Rebuild(road), Rebuild(intersection), RebuildAll() |
RiverPath | A river. Profile, ReverseFlow, FlowsInto, Frames, SurfaceHeightAt, TrySampleFlow, Rebuild |
RiverFloater | Floats a Rigidbody on any river. Buoyancy, FlowGrip, FloatDepth, FloatPoints, InWater, LastSample |
TerrainCompositor | Shapes terrains. Find, FindOrCreate, RebuildAll, Rebuild(bounds), RestoreOriginalTerrain, TrySampleOriginalHeight |
RoadProfile, RiverProfile | Profile assets. Every setting has a property; call NotifyChanged after changing one from a script |
PathKnotData | Per-knot values: SetKnotValue(spline, PathKnotData.WidthKey, knot, value) with WidthKey, BankKey, DepthKey and SpeedKey |
PathFrame | A sample along a path: position, tangent, right, up, distance, widths, bank, depth, speed, curvature |
Reading the flow
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
| Event | When |
|---|---|
RoadPath.Rebuilt, RiverPath.Rebuilt, RoadIntersection.Rebuilt | After the mesh of that path is rebuilt |
TerrainCompositor.BeforeTerrainWrite | Before the compositor writes to a TerrainData |
TerrainCompositor.TerrainRebuilt | After an area of a terrain is rebuilt, with the area in world space |
TerrainCompositor.BaselineCaptured | When 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.