Table of Contents

Water Object

WaterObject is the main SceneComponent of the Dynamic Water Physics 2 for Unreal Engine. It handles all the aspects of simulating the interaction of the object with water.

Hierarchy

WaterObject needs to be attached as a child of UStaticMeshComponent. This is because the mesh data is used for simulation. Below are a few examples of blueprint hierarchies that can be used:

Simplest possible setup. WaterObject1 is using StaticMesh1 to retrieve mesh data and is also applying forces to StaticMesh1.
Nested setup. WaterObject1 is using StaticMesh1 to retrieve mesh data and WaterObject2 is using StaticMesh2 to retrieve mesh data, while both WaterObjects are appying forces to StaticMesh1.

WaterObject always retrieves mesh data from the first parent UStaticMeshComponent. However, the resulting forces are applied to the first UPrimitiveComponent in the hierarchy with Simulate Physics enabled that the script comes across, iterating from itself towards the scene root. An example of this:

Cube in this image has Physics Enabled set to False which means that both WaterObjects will be applying forces to the first parent UPrimitiveComponent which has it enabled - in this case StaticMesh1.

Mesh Data

WaterObject uses mesh data (vertices and triangles) to calculate the correct physics forces. This means that the performance of the WaterObject is directly proportional, O(n), to the number of triangles present on the mesh. Most LOD0 meshes have an unnecessarily high number of triangles for this use so using LODs is recommended.
There are two settings:


Generally adequate triangle count for different shapes:

For most shapes around 16-32 triangles is adequate and as long as the mesh roughly represents the object shape increasing the number of triangles will not improve the quality of the simulation.

Setting up LODs

LODs in Unreal can be edited by double-clicking the mesh in the Content Browser and selecting the LOD through the LOD Picker (Details sidebar):

Mesh editor with the preview for LOD 3 enabled for the Barrel prop mesh from the demo scene.

If the LOD dropdown does not have any options, make sure that the LOD Group is set (under LOD Settings foldout).

To adjust the number of triangles on the LOD adjust the Percent Triangles slider until the wanted triangle count is achieved. By default with the Mesh LOD of WaterObject set to -1 the highest LOD will be used, which in this case is LOD 3.

Water Data

By default WaterObject uses Default Water Height, Default Water Normal and Default Water Flow. These three settings can be adequate if the water is flat and uniform across the scene. However, if using a non-flat water WaterObject needs to know where the water is. This is done through WaterData components. The base class is UWaterDataBase which can then be overridden to implement support for different water systems, such as the included UWaterDataUnrealWater.

Step-by-step Setup Guide

A quick step-by-step guide for setting up the barrel from the demo:

Basic Setup
  1. Right click in the Content BrowserBlueprint Class to create a new empty blueprint.
  2. Add ComponentStatic Mesh.
  3. Drag the newly created StaticMesh over the current scene root to make it a new root and rename it to BarrelStaticMesh.
  4. Select the BarrelStaticMesh and asign the Static Mesh under the Details panel to barrel_Oildrum-ref.
  5. Tick Simulate Physics field under the same Details panel.
  6. Add ComponentWaterObject and rename it to BarrelWaterObject.
  7. Place the blueprint into the scene and press Play. The barrel will now float at world position of Z = 0.
Adjusting LODs
  1. Double click on the Static Mesh to open the mesh editor.
  2. Under DetailsLOD Picker select lowest lod. By default this is LOD 3.
  3. Adjust the Percent Triangles until the mesh has lowest number of triangles while still keeping its general shape.
Adding WaterData
  1. Click on Add Component and then on Water Data Base or Water Data Unreal Water, depending on the water used.
  2. If using Unreal Water there is a known issue as of Unreal 4.27 where the BuoyancyManager will not register the object as in water if it starts partially or fully submerged, which means that the object needs to be above the water at the start.
End result of the setup guide.