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.
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.
Set r.Water.WaterMesh.ForceRebuildMeshPerFrame to 1
Open the water surface material (WaterBodyActor → WaterBodyComponent → Water Material), set “UseFixedZ” to true, so that it updates with the frame’s rebuilt mesh.
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.
Locate the “WaterBodyData” material function (Engine/Plugins/Water Content/Materials/Functions).
Open Water surface material and post process material, both needs to have “UseFixedZ” to true
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.
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.
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
I have been struggling with this recently myself and all of the suggestions here have not resulted in anything positive. I think perhaps this works when the only thing that is changing is the Z level but if you alter the spline at all such that it moves outside of the original bounds, all you get is a “shadow” and not a properly rebuilt mesh. What I was attempting to do is basically alter the flow of a river and there isn’t anything in the specs that indicate you couldn’t do this.
I can create a new river based on a template actor and place it wherever I want and I can even effect the Z without a problem, but I can’t affect the spline points and have the mesh regenerate and show visually (certainly the code thinks its regenerating, but it doesn’t render - at least not outside of the original bounds.
I’m using 5.3.2 as a basis and I figure this is either some kind of bug or its just a design constraint (I won’t say undocumented since none of this is documented).
If either of you have any updated thoughts based on your work since these posts I’d love to hear about them
So I’m pretty sure after closer inspection that if you move the spline points in a way that would deform the mesh then it won’t get displayed properly because the mesh needs to get recooked. It seems that there are two different levels of mesh building:
Editor triggered when OnWaterBodyChanged is called when the change type is not interactive (which is the case when you use editor to drag a spline point and lift up/finish action triggered)
Runtime - there is a GenerateMeshes() call in UpdateBody which is a bit of a misnomer in that it looks as though its not really generating meshes but rather updating associated metadata
I’m afraid at this stage you can’t update water splines during runtime if the nature of the update results in an altered shape. All meshes that have their structure altered will not render, but those that were unaffected will still render. You can move around the actor, I suspect even rotate it - but because the OnWaterBodyChanged method triggered by the Editor calls UpdateWaterBodyRenderData and this ultimately cooks using MeshBuilder.BuildWaterInfoMeshes which is well entrenched in editor-only logic - would be hard to pull it out and make accessible to game runtime.
I do wonder what their plan is for this plugin. Its been "experimental " now since at least 5.1. Would think its time to clean it up and make it official. If any Epic folks are reading these it would be very handy to allow the spline meshes to be properly updated at runtime.
With epics built in system NOTHING can be changed at runtime.
You would need to develop your own thing to deal with it at runtime.
And for a river, it wouldn’t be paricularly hard so long as you realize the landscape won’t automatically change at runtime on its own either.
Your biggest enemy in making a complimentary system yourself is the CPU/Collision side.
You may be better off with any of the voxel plugins and making your custom river thing affect the voxel stuff. That at least is meant to be changed at runtime, so its likely a bit easier to deal with.
Re the experimental.
There’s stuff in engine thats been that way since 2010… they have no plans at epic, and the ones they do have are bad. Look at the state of the engine… Tim is more interested in f*king with Apple over Twitter than in having the people he pays perform decent work…
I was struggling with this for about 1½ hours. Saw quite a few posts about the “UseFixedZ” parameter but nothing was working. What fixed it for me was running the ForceRebuildMeshPerFrame command. Thank you!