Stylized Water 3 – River Modeler Documentation

Stylized Water 3 - River Modeler (Extension)

River Modeler for Stylized Water 3
Version: 1.0.1
Review

4.Scripting #

Familiarity with C# and OOP programming is assumed. Support cannot be extended to coding help. Some specific functionality and use cases really need to be handled on a project-specific basis with some creative thinking.

Scripts are in the StylizedWater3.RiverModeler namespace.

Events

There are two events to subscribe to, that fire before the river is rebuild and after…
RiverModeler.onPreRebuildRiver += OnRiverRebuild;
RiverModeler.onPostRebuildRiver += OnRiverRebuild;

These callbacks returns the Instance being modified and the ChangeFlags (specifying which aspect prompted the rebuild, if any).

Never call the Rebuild() function from these methods! This creates an infinite loop.

Physics Trigger callbacks

On the River Modeler component, under the Output section you can enable the “Box Triggers” option. This will set up a Box Collider trigger on each river segment.

You can then, in any other script, subscribe to these static events:

  • RiverSegment.onTriggerEnter(RiverSegment segment, Collider other);
  • RiverSegment.onTriggerStay(RiverSegment segment, Collider other);
  • RiverSegment.onTriggerExit(RiverSegment segment, Collider other);

These events are excellent to handle behaviour specific to rivers, such as detecting the nearest position to the spline (eg. finding a drinking spot).

Note that you can access the river the segment belongs to through its River property. Which in turn has a Owner property (the River Modeler) component. Traversing the hierarchy up this way allows you to even access the Spline it was made with.

Sampling the river surface

Generally, you can sample the same spline used by a river to get its position/direction/normal using Spline.Evalutate(t);. But the River Modeler component contains a helper function that simplifies this:

RiverModeler.FindNearestPointOnRiver(float3 worldPosition, out float3 point, out float3 direction, out float3 normal, out float t, float sampleDistance = 1f);

This function is fairly optimized, since it first checks if the input position falls within a segment’s bounds, before actually sampling the spline. Plus, it only analyzes the spline section the segment belongs to, not the entire spline!

This is excellent to use for controlling particle effects, swimming behaviour or buoyancy physics!

This method may not work if you’re using a streaming system for the river segments. Since a reference to their parent river and the River Modeler component (referencing the Spline Container) may be lost.

Procedural Splines

If you’re looking to generate a spline from a set of points, that is certainly possible. Unity’s Splines API contains this function which can be used for it:

FitSplineToPoints(List<float3> positions, float errorThreshold, bool closed, out Spline spline);

If you have the Spline Extensions asset installed, you can use this multithreaded variant that’s x26 times faster:

CreateSplineFromPoints.Execute(List<float3> positions, float errorThreshold, bool closed, out Spline spline, float3 up = default);

The Spline Mesher Pro documentation has a section about best practise for this, worth reading.

Yes No Suggest edit
Last updated on September 2, 2026
0 of 0 users found this section helpful
If you're familiar with this asset, please consider leaving a review!
Your support is what makes complementary updates possible!
Suggest Edit