create a river by use of python script, AI copilot and some ue 5 10xpositions for the splines.

Hello, Im with quite little experience in UE 5.4. Working in win 11, ue5.5/5.44
I asked copilot to make a python script for creating a river, taking thee 10 positions as river placement guideance.

After first run of script, world looked like in attached river1.png and following error:
LogWaterEditor: Error: Invalid River spline mesh component count.
LogWaterEditor: Error: Error in setup River spline render material for Water Brush. Aborting CaptureRiverDepthAndVelocity.
…which neither copilot nor I am able to find a solution.

After a bit vague hints, I had to manually enable some water mesh in the WaterBodyRiver in editor, something that could remind of a river showed up (accordingly to the 10 input positions, at screen.
see attached river2.png.

I would appreciate if someone could have a glimt at the image and give some feedback of the result, based on the 2 images:

  1. Howto fix the error above, some hints to solution?

  2. I expected river to blend in between both sides of the river route. How do I prepare landscape for this?

  3. I wonder if its possible NOT to view the blue color of each side of river?
    Deleting the WaterZone does that, but thats not an option.

  4. To the experienced ones, what should be the absolute least settings in editor WaterBodyRiver
    to build further out manually in future, regarding the river properties?

I attach the python code, made by an AI copilot, allthough it shouldnt be needed.

Thank You


CODE;
import unreal

def create_river_from_points(river_points, river_width):
“”"
Creates a WaterBodyRiver actor and sets up its spline along the given points.

Args:
    river_points (list of unreal.Vector): The list of points defining the river path.
    river_width (float): The width of the river.
"""
# Spawn the WaterBodyRiver actor
river_actor = unreal.EditorLevelLibrary.spawn_actor_from_class(
    unreal.WaterBodyRiver, river_points[0], unreal.Rotator(0, 0, 0)
)
if not river_actor:
    unreal.log_error("Failed to create WaterBodyRiver actor.")
    return

# Get the spline component from the river actor
spline_component = river_actor.get_water_spline()

if not spline_component:
    unreal.log_error("Failed to get the Water Spline Component.")
    return

# Clear existing spline points
spline_component.clear_spline_points()

# Add the provided points to the spline
for index, point in enumerate(river_points):
    spline_component.add_spline_point_at_index(
        point, index, unreal.SplineCoordinateSpace.WORLD, update_spline=False
    )

# Update the spline
spline_component.update_spline()

# Set the river width
for i in range(spline_component.get_number_of_spline_points()):
    spline_component.set_spline_point_type(i, unreal.SplinePointType.CURVE, False)

# Update the spline again to apply changes
spline_component.update_spline()

# Log success
unreal.log(f"River created with {len(river_points)} points and width {river_width}.")

def main():
# Your river points with updated Z value
river_points = [
unreal.Vector(13420.0, 58490.0, -18500.0),
unreal.Vector(15000.0, 57090.0, -18500.0),
unreal.Vector(18300.0, 52300.0, -18500.0),
unreal.Vector(23290.0, 47930.0, -18500.0),
unreal.Vector(25960.0, 45330.0, -18500.0),
unreal.Vector(28060.0, 36190.0, -18500.0),
unreal.Vector(30950.0, 29950.0, -18500.0),
unreal.Vector(32650.0, 26250.0, -18500.0),
unreal.Vector(32740.0, 21370.0, -18500.0),
unreal.Vector(30990.0, 16620.0, -18500.0),
]

river_width = 2048.0  # Adjust the width as needed (in Unreal units, centimeters)

# Create the river with the specified points
create_river_from_points(river_points, river_width)

if name == “main”:
main()

Seems like the spline points are told not to have curve values - which is likely bad on the built in river system.
The curve definitions are used to determine the water flow if they ever implemented that to work like the videos of the system they shared 4 years+ ago.

1 Like

Thank You. To me the spline route draws a good horizontal curve, but its perhaps that curve you are talking about? I will search for keys "spline points enable curve values " for a hopefully closer approach for the river creating.