> For the complete documentation index, see [llms.txt](https://docs.shadersource.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.shadersource.io/assets-and-plugins/ocean-tool-2/tutorials/water-in-blueprints.md). Agents can also search and read this documentation through its [MCP server](https://docs.shadersource.io/~gitbook/mcp).

# Water in Blueprints

Use the ocean from Blueprint - read the water's height, change the sea while the game runs, and make a splash.

Everything the editor mode sets is a property of the ocean actor, and the actor has Blueprint functions for the things a game needs at run time: where the water is, changing the weather, and disturbing the surface. This tutorial builds four small examples.

|                  |                                                                 |
| ---------------- | --------------------------------------------------------------- |
| **Time**         | About 15 minutes                                                |
| **You need**     | A level with an ocean, and some Blueprint experience            |
| **You will use** | The **Ocean** actor's functions, under the **Ocean 2** category |

{% hint style="info" %}
**To float something, you do not need any of this.** The **Ocean 2 Buoyancy** component and the floating object actor already do it properly - see [Buoyancy and Boats](https://docs.shadersource.io/assets-and-plugins/ocean-tool-2/tutorials/buoyancy-and-boats.md). Read the water yourself when you want something else: a camera that stays above the waves, an AI that knows where the surface is, a hazard that reacts to the tide.
{% endhint %}

## Get the ocean

Every example starts by finding the ocean.

{% stepper %}
{% step %}

### Find it once

In **Begin Play**, add **Get Actor Of Class** and set its class to **Ocean** (`SH_Ocean2WaterBody`).
{% endstep %}

{% step %}

### Keep it

Promote the result to a variable - call it `Ocean`. Finding an actor is too slow to do every frame.
{% endstep %}
{% endstepper %}

## Example 1 - Is this point under water?

{% stepper %}
{% step %}

### Ask for the water's height

From your `Ocean` variable, drag out **Get Water Height At**. Give it a world position - the actor's location, say.

It returns the world Z of the water surface at that point, waves included, read from the ocean's exact copy of the waves it is drawing.
{% endstep %}

{% step %}

### Compare

Compare the returned height with your point's Z. If the point is lower, it is under water.

For how deep, subtract: the water's height minus the point's Z is its depth below the surface.
{% endstep %}
{% endstepper %}

The related functions:

| Function                     | Returns                                                                                                                                                       |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Get Water Height At**      | World Z of the surface at a position, waves included.                                                                                                         |
| **Get Wake Height At**       | The extra height of boat wakes there, in cm. Add it to the height. Zero unless **Floating things ride wakes** is on.                                          |
| **Get Water Normal At**      | Which way the surface faces there - for tilting something to lie on the water.                                                                                |
| **Get Surface Height**       | World Z of the *still* surface: the sea level, with no waves.                                                                                                 |
| **Get Still Water Depth At** | How deep the still water is over the ground at a position (negative over land), as its output. It returns false where it has no answer: away from the camera. |
| **Is Water Hidden At**       | Whether the water has been painted away there with **Hide water**.                                                                                            |

## Example 2 - Keep a camera above the waves

{% stepper %}
{% step %}

### Read the height under the camera, every frame

In **Event Tick**, call **Get Water Height At** with the camera's location.
{% endstep %}

{% step %}

### Hold the camera above it

Take the larger of the camera's own Z and the water's height plus a margin - 50 cm is a good start - and set the camera's Z to it.
{% endstep %}
{% endstepper %}

The camera now rises over each wave instead of dipping through it.

## Example 3 - Change the weather while the game runs

The same functions the editor mode calls are open to Blueprint, and the settings that depend on them follow as they do in the editor.

| Function                                      | What it does                                                                                                                                                                                                                   |
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Apply Beaufort Force**                      | Sets the wind strength, 0 to 12. Waves, foam and detail follow. Keeps the colour, the shoreline, the wind's heading and the wave clock.                                                                                        |
| **Apply Ocean Style**                         | Switches to another ocean style at the current force.                                                                                                                                                                          |
| **Set Wind Direction**                        | The way the wind sea travels, in degrees: 0 is +X, 90 is +Y.                                                                                                                                                                   |
| **Set Sea Colour**                            | Chooses a sea colour by its id: the colour's name with no spaces, such as `CaribbeanTurquoise` or `NorthSea`; `Custom`; `UsePreset`; or `None` for the style's own colour.                                                     |
| **Set Foam Type**                             | Breaking foam or Crest trail.                                                                                                                                                                                                  |
| **Set Choppiness Scale**, **Set Wave Spread** | How sharp the crests are, and how long they run.                                                                                                                                                                               |
| **Set Surface Height**                        | Moves the sea level. In play a baked shoreline catches up within about a second, worked out off the game thread, so a tide can call it every frame. In the editor, or with no bake, each call works the shoreline out at once. |

{% stepper %}
{% step %}

### Bring on a storm

Add a **Timeline** with one float track that runs from 3 to 10 over sixty seconds.
{% endstep %}

{% step %}

### Feed it to the ocean

On the timeline's **Update**, call **Apply Beaufort Force** with the track's value. The sea builds from a gentle breeze to a storm over a minute.
{% endstep %}
{% endstepper %}

To apply a whole saved sea at once, call **Apply To** on a preset asset (an **Ocean 2 Profile**) with the ocean as its target, then **Rebuild Ocean** on the ocean.

{% hint style="warning" %}
After changing several properties directly - rather than through the functions above - call **Rebuild Ocean** once. It rebuilds the waves, the mesh and the materials from the current settings.
{% endhint %}

## Example 4 - Make a splash

{% stepper %}
{% step %}

### Turn on wakes

Out at sea a splash is drawn through the wake, so the ocean's **Wakes** must be on (**Simple > Buoyancy & Wakes**). Where the simulated shore runs, the splash goes into the simulated water itself, with Wakes on or off.
{% endstep %}

{% step %}

### Call Add Splash

Where something hits the water, call **Add Splash** with the world location, a **Radius** in cm and a **Speed** - how fast it went in, in cm a second.

A ring spreads from the point, with white water where it went in. Where the simulated shore runs, it is its water that rings, turns white and throws spray.
{% endstep %}
{% endstepper %}

For a push with no white water - an oar, a paddle, a footstep - use **Press Shore Water**: it presses the simulated shore's water down at a point for a moment.

## What moves with the water

**Get Water Flow At** returns the water's horizontal flow at a position, in cm a second: the swell's to and fro, the surf carrying things in, and the wash up the sand and back. It is what drifting floating objects are carried by.

Add it to an actor's velocity and that actor drifts with the sea. It works round the camera, where the ocean keeps a copy of the water it is drawing.

## Things to know

* **The first moments of play.** Physics reads the water as drawn only once that copy is ready - a fraction of a second after play starts, a few seconds at most. **Is Physics Water Ready** tells you when. The buoyancy component waits for it by itself.
* **Servers.** A dedicated server has no drawn water. Its height queries read the open sea's waves from the exact CPU copy, so a server floats a boat on the same open-sea waves its clients see - without the shoreline's waves.
* **Several oceans.** Each function belongs to one ocean actor. With more than one in a level, find the one you mean.
* **Python.** Every function here is also in the editor's Python API under the same name in snake case: `get_water_height_at`, `apply_beaufort_force`, and so on.

## Where next

* [Ocean 2 Actor](https://docs.shadersource.io/assets-and-plugins/ocean-tool-2/how-to-use/ocean-2-actor.md) - what the actor owns.
* [Buoyancy and Wake Components](https://docs.shadersource.io/assets-and-plugins/ocean-tool-2/how-to-use/boats-buoyancy-and-wakes/buoyancy-and-wake-components.md) - the components that float and wake your own actors.
* [Swimming](https://docs.shadersource.io/assets-and-plugins/ocean-tool-2/how-to-use/boats-buoyancy-and-wakes/swimming.md) - the swimming component's functions and events.
