Build a Beat-Box Island with Patchwork
Tutorial beginner compiles

Build a Beat-Box Island with Patchwork

Updated beginner Code verified

Build a Beat-Box Island with Patchwork

Welcome to the world of game sound! Have you ever wanted your island to have music that changes when you jump? Or lights that flash to the beat? You can do this with Fortnite Patchwork. It is like a digital mixing board for your island.

In this tutorial, we will make a simple drum machine. You will place a device down. Then, you will use Verse code to start the music. You will also use code to stop the music when a player touches a button. It is easy and super fun.

What You'll Learn

  • What Fortnite Patchwork is.
  • How to find Patchwork devices in UEFN.
  • How to use Verse to turn sound on and off.
  • How to connect your code to a game device.

How It Works

Think of Patchwork like a set of musical instruments. You have a drum kit. You have a keyboard. You have a speaker. In Fortnite Creative, you connect these with virtual cables. In UEFN, the devices work the same way. The big difference is how you control them.

In Creative, you use cables to connect triggers to music. In UEFN, you can use cables. But you can also use Verse code. Verse is like a remote control. It lets you say "Play music now!" or "Stop music now!" using simple commands.

We will use two main things:

  1. The Patchwork Device: This makes the sound. It is a special object in your level.
  2. The Verse Script: This tells the device when to play.

Imagine a light switch. The light bulb is the Patchwork device. The switch is your Verse script. When you flip the switch, the light turns on. When you flip it off, the light turns off. We will do this with sound!

Let's Build It

First, let's get the device ready. Open your island in UEFN. Open the Content Browser. Search for "Patchwork". You will see a folder called "Patchwork". Open it. You will see many devices. Look for Patchwork Music Player. Drag it into your level.

Now, let's write the code. This code will start the music when the game starts. It will also stop the music if a player hits a specific wall.

Copy this code into a new Verse file. Name it BeatBoxScript.

# This is the main script for our beat box island.
# It controls the music player.

using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/Patchwork }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# We create a new type called BeatBox.
# This is like a blueprint for our island logic.
BeatBox := class(creative_device):

    # This is a variable for our music device.
    # It holds the Patchwork Music Player.
    # Drag your Patchwork Music Player device onto this property
    # in the UEFN Details panel after uploading the script.
    @editable
    MusicPlayer : speaker_device = speaker_device{}

    # This is a variable for the stop trigger device.
    # It listens for a player stepping on it to stop the music.
    # Drag a Trigger device (your "StopWall") onto this property
    # in the UEFN Details panel.
    @editable
    StopTrigger : trigger_device = trigger_device{}

    # This function runs when the game starts.
    OnBegin<override>()<suspends>: void =

        # We subscribe to the StopTrigger's TriggeredEvent.
        # When a player activates the trigger, OnPlayerHitStopWall runs.
        StopTrigger.TriggeredEvent.Subscribe(OnPlayerHitStopWall)

        # We tell the device to start playing.
        # This is like flipping the switch on!
        MusicPlayer.Enable()

    # This function runs when a player hits the stop wall.
    # The trigger_device passes the activating agent here.
    OnPlayerHitStopWall(Agent : ?agent): void =
        # We check if the agent is a fort character (a player in the world).
        if (A := Agent?, Character := A.GetFortCharacter[]):
            # We stop the music!
            MusicPlayer.Disable()```

### Walkthrough of the Code

Here is what each part does.

The `using` lines bring in tools from Fortnite and Verse. They are like tools in a toolbox. You need them to build.

`BeatBox := class(creative_device):` creates our main script. Think of this as the brain of the island. All island scripts extend `creative_device` in real Verse.

`@editable` marks the two variables below it so they appear as slots in the UEFN Details panel. After you upload your script, drag your placed devices from the Outliner into those slots. No runtime searching is needed.

`MusicPlayer : patchwork_music_player = patchwork_music_player{}` creates a slot for our Patchwork device. It starts empty. You fill it in the Details panel.

`StopTrigger : trigger_device = trigger_device{}` creates a slot for a **Trigger** device. Place a Trigger device in your level where you want the "stop wall" to be, then drag it into this slot.

`OnBegin<override>()` is a special function. It runs automatically when the game begins. This is perfect for starting music!

`StopTrigger.TriggeredEvent.Subscribe(OnPlayerHitStopWall)` sets up a listener. When a player walks into the Trigger device, it calls `OnPlayerHitStopWall` automatically.

`MusicPlayer.Play()` tells the device to play. The music begins!

`if (Character := Agent.GetFortCharacter[]):` checks if the thing that activated the trigger is a player character. This stops other things from stopping the music.

`MusicPlayer.Stop()` stops the music. The beat cuts out.

## Try It Yourself

Now it is your turn to make it better!

**Challenge:** Add a second button. When a player hits a "StartWall", the music should start again.

**Hint:** You already have the `Play()` command. You just need to add a new `@editable` trigger device for the "StartWall" and subscribe a new handler to its `TriggeredEvent`. You can copy the `OnPlayerHitStopWall` function and change the name. Call it `OnPlayerHitStartWall`. Inside, call `MusicPlayer.Play()`.

Did it work? High five! You just programmed music into your game.

## Recap

Patchwork devices make music and visuals. They work in UEFN just like in Creative. You can control them with Verse code. Use `Play()` to play music. Use `Stop()` to stop it. Use `@editable` to connect your script to placed devices in the Details panel. You are now a game audio engineer!

## References

*   https://dev.epicgames.com/documentation/en-us/fortnite/using-fortnite-patchwork-in-unreal-editor-for-fortnite
*   https://dev.epicgames.com/documentation/en-us/uefn/using-patchwork-in-unreal-editor-for-fortnite
*   https://dev.epicgames.com/documentation/en-us/fortnite/composing-with-patchwork-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/composing-with-patchwork-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/uefn/editing-landscape-material-in-unreal-editor-for-fortnite

Verse source files

Turn this into a guided course

Add using-patchwork-in-unreal-editor-for-fortnite 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.

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.

Comments

    Sign in to vote, comment, or suggest an edit. Sign in