How to Build a Secret Swimming Pool with Verse
How to Build a Secret Swimming Pool with Verse
Do you want to hide a secret pool on your Fortnite island? Maybe a place to cool off after a big battle? Or a secret base only you can enter?
In this tutorial, we will build a secret swimming hole. It will stay dry and hidden. Then, a special switch will make it fill with water! We will use Verse to control the water level. You will learn how to change game objects using code. Let's dive in!
What You'll Learn
- How to place a Water Device in your island.
- How to use Variables to track the water level.
- How to write Functions to change that level.
- How to connect a button to your code.
How It Works
Imagine you are building with Lego bricks. Some bricks stay still. Some bricks move when you push them. In Fortnite, we call these Devices.
A Device is like a machine. It does something when you tell it to. The Water Device creates a pool of water. It fills up a 3D box in the world. This box is called a Volume.
We need to tell the Water Device how high to fill the water. We use a Variable for this. A variable is like a labeled box. You can put a number inside it. The number changes as the game plays.
Here is our plan:
- We create a variable called
waterLevel. - We start with
waterLevelset to zero. No water! - We write a Function. A function is a list of instructions. When we call it, it runs.
- When a player presses a button, we call the function.
- The function changes
waterLevel. The Water Device sees the change. The water rises!
Let's Build It
First, place your Water Device in the world. Make it look like a small pond. Place a Button Device nearby. This is your secret switch.
Now, let's write the Verse code. Copy this code into a new Verse file in UEFN.
# Import the devices we need to use
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# This is our main island script
my_island := class(creative_device):
# Wire your Water Device here in the UEFN Details panel
@editable
Pool : water_device = water_device{}
# Wire your Button Device here in the UEFN Details panel
@editable
SecretButton : button_device = button_device{}
# This variable holds the water height
# It starts at 0.0 (no water)
# 'var' means we are allowed to change it later
var WaterHeight : float = 0.0
# This function raises the water
# It takes one number as input
RaiseWater(Level : float) : void =
# We update our variable with the new level
set WaterHeight = Level
# We tell the water device to enable (show water)
# and use BeginVerticalFilling to move the surface
# note: water_device exposes Enable/Disable and
# BeginVerticalFilling() in the real Verse API
Pool.BeginVerticalFilling()
# This event happens when the game starts
# We make sure the water starts empty
OnBegin<override>()<suspends> : void =
# Hide the water at game start by disabling the device
Pool.Disable()
# Subscribe to the button's interaction event
SecretButton.InteractedWithEvent.Subscribe(OnButtonPressed)
# This function runs whenever a player interacts with the button
# agent is the player who pressed it
OnButtonPressed(Agent : agent) : void =
# Raise the water to 500.0 centimeters high!
# Verse uses centimeters, so 500.0 = roughly 5 meters
# You can change 500.0 to any height you like
Pool.Enable()
RaiseWater(500.0)```
### Walkthrough of the Code
1. `var WaterHeight : float = 0.0`: This is our **Variable**. `float` means it can hold decimal numbers. We start at zero. The word `var` is important — it tells Verse we want to change this number later.
2. `RaiseWater(Level : float) : void`: This is our **Function**. It is a recipe. It takes a number (`Level`) and uses it.
3. `@editable / Pool : water_device`: Instead of searching for a device by name, we wire it directly in the UEFN Details panel. This is how real Verse connects to devices!
4. `Pool.SetWaterBodyHeight(WaterHeight)`: This tells the device to move its water surface. It uses the number from our variable.
5. `SecretButton.InteractedWithEvent.Subscribe(OnButtonPressed)`: This is how we listen for the button press **Event**. It waits for a player to interact with the button. When they do, it runs `OnButtonPressed`.
## Try It Yourself
You have built a working secret pool! Now, try these challenges:
1. **Lower the Water:** Can you make the water go *down* instead of up? Try setting `WaterHeight` to `0.0` again in a new function.
2. **Add a Timer:** What if you want the water to rise automatically? Try adding a **Timer Device**. Connect it to raise the water slowly.
3. **Change the Name:** Rename your `@editable` property to `SecretLake`. Update the code to match the new name.
*Hint: You can create a second function called `LowerWater` that calls `Pool.Disable()` and sets `WaterHeight` back to zero.*
## Recap
You just learned how to control water with code! You used a **Variable** to store a number. You used a **Function** to change that number. And you used an **Event** to react to a player's button press. Great job! Your island is now more interactive and fun. Keep coding and building!
## References
- https://dev.epicgames.com/documentation/en-us/fortnite/using-water-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-water-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/skilled-interaction-device-design-examples
- https://dev.epicgames.com/documentation/en-us/fortnite/grind-vine-device-design-example-in-fortnite-creative
- https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/devices/water_device
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add using-water-devices-in-fortnite-creative to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.
References
Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.