Platforms that appear and disappear periodically are a staple of platforming game modes like obstacle courses. They require players to time their jumps to navigate to the next platform, and if they miss, they'll fall and have to start over.
By following this tutorial, you'll learn how to use Verse in Unreal Editor for Fortnite (UEFN) to create a platform that appears and disappears on a loop. The complete script is included at the end of this tutorial for reference.
Verse Language Features Used
loop
: The platform alternates between being visible and invisible until the game ends. This example uses the Verseloop
expression to continuously run this behavior.
Verse APIs Used
-
Sleep()
: With theSleep()
function, you can choose how long the platform will be in its invisible and visible states. -
Editable Properties: Two device properties are exposed to UEFN so you can customize them in the editor — a
creative_prop
reference for the platform and aToggleDelay
for theSleep()
function call.
Setting Up the Level
This tutorial uses the Verse Starter Template as its starting point. To get started, initialize a new project from the Verse Device feature example.
This example uses the following props and devices:
-
1 x Player Spawn Pad device: This device defines where the player spawns at the start of the game.
-
3 x Creative Prop: Creative props have several behaviors you can call with Verse, such as
Hide()
andShow()
to toggle the platform's visibility and collision. This tutorial uses the Airborne Hoverplatform A as the player-interactable platform, but feel free to change this to suit the needs of your experience.
Follow these steps to set up your level:
-
Drag one Airborne Hoverplatform A into your scene. Place it above the floor so the player will fall if they don't jump off the disappearing platform in time. In the Outliner, name the platform LoopingDisappearingPlatform.
-
Copy the platform twice, and place them on opposite sides of the first platform so that the player must time their jump. The player should have barely enough time to get to the other side.
-
Move the Player Spawn Pad onto one of the platforms. This is where the player will spawn when the game starts. Your level setup should look similar to this:
Creating the Verse Device
This example uses a Verse-authored device to define the behavior that toggles platform visibility. Follow these steps to create your Verse device and place it in the level.
-
Create a new Verse device named looping_disappearing_platform using Verse Explorer. For steps, see Create Your Own Device Using Verse.
-
Drag the looping_disappearing_platform device from the Content Browser into the level. For steps, see Create Your Own Device Using Verse.
Editing the Device Properties in UEFN
This section shows how to expose two device properties to UEFN so you can customize them in the editor:
-
A
creative_prop
reference to the Creative Prop that you placed in the level. -
A
float
constant to store how long the platform should be invisible/visible, namedToggleDelay
.
Follow these steps to expose these properties to the editor from the looping_disappearing_platform device you created in the previous section.
-
Open Verse Explorer and double-click looping_disappearing_platform.verse to open the script in Visual Studio Code.
-
To the
looping_disappearing_platform
class definition, add the following fields:-
An editable
float
namedToggleDelay
. This represents the time between toggling between visible and invisible. Initialize this value to2.0
, or two seconds.# The amount of time to wait before toggling visiblity of the platform. @editable ToggleDelay:float = 2.0
-
An editable
creative_prop
namedDisappearingPlatform
. This is the in-level platform that will disappear and appear periodically. Because your code doesn't yet have a reference to this object in the level, you'll instantiate this with an empty archetypecreative_prop{}
. You'll assign this reference to your floating platform later.# Reference to the platform in the level. @editable DisappearingPlatform:creative_prop = creative_prop{}
-
-
Your
looping_disappearing_platform
class fields should now look like this:using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/Diagnostics } # See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device. # A Verse-authored creative device that can be placed in a level looping_disappearing_platform := class(creative_device): # The amount of time to wait before toggling visiblity of the platform. @editable ToggleDelay:float = 2.0 # Reference to the platform in the level. @editable DisappearingPlatform:creative_prop = creative_prop{}
It's helpful to use the
@editable
attribute to expose values likeToggleDelay
to the editor from your scripts. This lets you customize their values in UEFN without having to rebuild Verse code each time, so you can iterate quickly and find values that fit your gameplay experience. -
Save the script in Visual Studio Code and compile your code to update the looping_disappearing_platform device in the level.
-
In the Outliner panel in UEFN, select the looping_disappearing_platform device to open its Details panel.
-
In the Details panel under Looping Disappearing Platform:
-
Set DisappearingPlatform to LoopingDisappearingPlatform (the Creative Prop you added to the level) by clicking on the object picker and selecting the Creative Prop in the viewport, or searching for the LoopingDisappearingPlatform in the search bar.
-
Set ToggleDelay to the number of seconds you want the platform to be visible/invisible. This value defaults to 2.0 since this is the value you defined earlier.
-
Hiding and Showing the Platform
Now that you've set up the level and devices, you can add logic to show and hide the platform. Follow these steps to add this behavior to the looping_disappearing_platform device:
-
The
creative_prop
class has two methods to toggle its visibility:Hide()
andShow()
. Back in Visual Studio Code, InOnBegin()
, callHide()
and thenShow()
on yourDisappearingPlatform
.# Runs when the device is started in a running game OnBegin<override>()<suspends>:void= # Make the platform invisible. DisappearingPlatform.Hide() # Make the platform visible. DisappearingPlatform.Show()
If you run this code, you won't see the platform disappear and reappear because the calls to
Hide()
andShow()
occur immediately after each other. -
To make the platform stay in a visible/invisible state longer, you need to add a delay before each
Hide()
andShow()
call usingSleep()
. TheSleep()
function suspends a routine's execution, and you specify the amount of time (in seconds) to suspend execution by passing in afloat
argument to the function. CallSleep()
before eachHide()
andShow()
call, passing theToggleDelay
you defined earlier.# Runs when the device is started in a running game OnBegin<override>()<suspends>:void= # Wait for ToggleDelay seconds. Sleep(ToggleDelay) # Make the platform invisible. DisappearingPlatform.Hide() # Wait for ToggleDelay seconds. Sleep(ToggleDelay) # Make the platform visible. DisappearingPlatform.Show()
If you run this code, the platform will be invisible for two seconds (the amount defined by
ToggleDelay
) before it becomes visible for the rest of the game.The
Sleep()
function can only be called in an asynchronous context. TheOnBegin()
method is already an asynchronous context since it has thesuspends
specifier, so you don't need to do anything further. To learn more about thesuspends
specifier, see Specifiers and Attributes. -
To make the platform alternate between visible and invisible for as long as the game is running, you can use the
loop
expression. Usingloop
repeatedly runs the code inside theloop
expression, unless the code is interrupted with abreak
. In this example, you want to toggle the visibility of the platform for as long as the game is running, so there's no need to add abreak
expression to exit theloop
. Add aloop
expression at the start ofOnBegin()
, and indent the rest of your code to be inside the loop. YourOnBegin()
method should look like this:# Runs when the device is started in a running game OnBegin<override>()<suspends>:void= loop: # Wait for ToggleDelay seconds. Sleep(ToggleDelay) # Make the platform invisible. DisappearingPlatform.Hide() # Wait for ToggleDelay seconds. Sleep(ToggleDelay) # Make the platform visible. DisappearingPlatform.Show()
-
Save the script and click Verse, and then Build Verse Code to compile the code.
-
Click Launch Session in the UEFN toolbar to playtest the level.
When you playtest your level, your platform should appear and disappear every two seconds for as long as the game is running.
Complete Script
The following code is the complete script for making a platform disappear and appear on a loop.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
# A Verse-authored creative device that can be placed in a level
looping_disappearing_platform := class(creative_device):
# The amount of time to wait before toggling visiblity of the platform.
@editable
ToggleDelay:float = 2.0
# Reference to the platform in the level.
@editable
DisappearingPlatform:creative_prop = creative_prop{}
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
loop:
# Wait for ToggleDelay seconds.
Sleep(ToggleDelay)
# Make the platform invisible.
DisappearingPlatform.Hide()
# Wait for ToggleDelay seconds.
Sleep(ToggleDelay)
# Make the platform visible.
DisappearingPlatform.Show()
On Your Own
By completing this tutorial, you've learned how to create a device using Verse that toggles the visibility of a platform for as long as the game runs.
Using what you've learned, try the following:
-
Duplicate the setup with the looping_disappearing_platform device and Prop, and try different
ToggleDelay
timings to create a longer series of platforms. -
Apply the same concepts to periodically call functions on other objects, such as the Prop Mover device.