Water plugin - Movable water bodies?

Hey!

Has anyone experience changing the water bodies at runtime? I am trying to change the location/shape of the coastline during the game.

I have tried setting the console variable r.Water.WaterMesh.ForceRebuildMeshPerFrame as suggested in this video, but it doesn’t seem to change anything.
I tried both changing the location of the WaterBodyOcean as well as changing the location of individual spline points, but the water mesh stays the same.

Any help would be appreciated.

Any luck with this? I am trying to do the same thing!

I figured out how to get that command to work; in the Sequencer/Movie render Queue at least. You need to add it to the Console Variables Setting and set it to 1.

Leaving this here if anybody is also trying to adjust ocean level during runtime. After hours of digging into the Water system I figured out a way.

There are 2 ways to achieve this:

Method 1:
Use command variables to force mesh update per frame (as @Psy2099 mentioned above)
This is easier. Downside is that this doesn’t update post-process materials, so if you’re not going underwater this is fine.

  1. Set r.Water.WaterMesh.ForceRebuildMeshPerFrame to 1
  2. Open the water surface material (WaterBodyActor → WaterBodyComponent → Water Material), set “UseFixedZ” to true, so that it updates with the frame’s rebuilt mesh.
  3. Set the component’s mobility to movable in BP to movable, then simply set the height of water body using BP, it shoud update.

Method 2:
Change the internal material setup to force water render at desired height.
This is simpler, as it takes care of water surface and post-process materials altogether. Basically we are setting the MPC parameter, and then changing the water material to adjust height according to the parameter. This only takes care of the rendering part, so if your waterbody needs to interact with objects, you’ll need to combine method 1&2.

  1. Locate the “WaterBodyData” material function (Engine/Plugins/Water Content/Materials/Functions).
  2. Replace “FixedZHeight” parameter node to CollectionParameter. Collection: MPC_Water, Parameter Name: WaterZ
  3. Open Water surface material and post process material, both needs to have “UseFixedZ” to true
  4. Set material parameter collection’s value using “Set Scalar Parameter Value” in BP. Set “WaterZ” value to your desired height. The water should render at the height without the need of moving/rebuilding mesh.
2 Likes

Thank you for leaving this here, it has been a big help to me so far. I’m using 5.3.2 and I have done what you detailed in option 2, but my post-process volume does not move. I have enabled “UseFixedZ” on both the post-process volume and the post-process material, but neither one has any effect on the height.
I did notice that my “WaterBodyData” is just slightly different by default and I’m wondering if that is it. Instead of “IsLODMaterial” mine has “UseWaterInfoTexture” and the line from the “FixedZHeight” node now goes to false instead of true, so I was wondering if you had encountered this and knew of an updated way to fix this.

I wrote this on 5.1/5.2 so maybe there’s been some changes since.
If that is the case then try setting your “UseFixedZ” parameter to false.

The idea is, both shaders would sample the water level using “WaterBodyData” function to get the correct water level. So if we override the fixed water level and offset the output, both the post process material and the water shader would get updated to the desired water level.
Since the replaced FixedZHeight node goes to false, you should set the parameter to false after you replace the node, to properlly offset the level. I didn’t test it but I’m guessing this is the issue.

Hopefully this helps

I don’t think changing the MPC value automatically updates the simulation results for the system.

Should people need or expect physics on top of it, you likely need to alter the function that provides the height value back to be offset by the same amount you offset the mesh.

Yes this only takes care of the rendering part. If people need physics and other simulation functionalities, force rebuild mesh might help although I didn’t test it