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:
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:
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:
Mesh LOD
- defaults to -1 which tells the script to use the highest available LOD (lowest detail).Mesh Section
- defaults to 0 and tells the script which mesh section to use.
Generally adequate triangle count for different shapes:
- Cube - 12 triangles.
- Sphere - 12-24 triangles
- Concave Shapes - ~32 triangles.
- Ship Hull - ~64 triangles but can range from 32 to 128 depending on size and required detail.
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):
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
.
- UWaterDataBase - supports single flat water surface with an option to assign a Water Height Reference Actor which will then be used as the water height reference.
- Excellent performance since the water level is the same across the world.
- UWaterDataUnrealWater - adds support Unreal Water plugin (Unreal 4.26+).
- Water height, normals and flow querying is supported.
- Higher CPU overhead from using the flat water.
- On small props and other non-essential items
WaterObject
⇒Query Single Point
can be used to maximize performance.
Step-by-step Setup Guide
A quick step-by-step guide for setting up the barrel from the demo:
Basic Setup
- Right click in the Content Browser ⇒ Blueprint Class to create a new empty blueprint.
- Add Component ⇒ Static Mesh.
- Drag the newly created StaticMesh over the current scene root to make it a new root and rename it to BarrelStaticMesh.
- Select the BarrelStaticMesh and asign the
Static Mesh
under the Details panel tobarrel_Oildrum-ref
. - Tick Simulate Physics field under the same Details panel.
- Add Component ⇒ WaterObject and rename it to BarrelWaterObject.
- Place the blueprint into the scene and press Play. The barrel will now float at world position of Z = 0.
Adjusting LODs
- Double click on the
Static Mesh
to open the mesh editor. - Under Details ⇒ LOD Picker select lowest lod. By default this is LOD 3.
- Adjust the Percent Triangles until the mesh has lowest number of triangles while still keeping its general shape.
Adding WaterData
- Click on
Add Component
and then onWater Data Base
orWater Data Unreal Water
, depending on the water used. - 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.