This tutorial shows you how to build your first Fortnite template ability: a "Spicy Sprint" ability that applies a damage-over-time effect and a speed boost simultaneously.
You'll create the Verse script that defines the template ability, build an item that gives it, and create a device that grants the item to the player.
Prerequisites
You must enable Scene Graph Experimental Features and Custom Items and Inventory in the Project Settings to use template abilities and complete this tutorial.
Additionally, it's useful to review the Custom Items and Inventories documentation for additional context, but it isn't required.
Create the Verse Script
In this section, you'll create the Verse script that holds all the code for this tutorial.
On the menu bar, select Verse > Verse Explorer.
In the Verse Explorer, right-click on your project and select Create Verse File.
In the Create Verse Script window, name the script template_ability_example and select Create Empty.
On the menu bar, select Verse > Open Project in VS Code.
Input the following code to add required modules:
Verseusing { /Fortnite.com/Abilities } using { /Fortnite.com/Devices } using { /Fortnite.com/Itemization } using { /UnrealEngine.com/Abilities } using { /UnrealEngine.com/Itemization } using { /Verse.org/SceneGraph } using { /Verse.org/Simulation }Add the utility function that returns a player's weapon hotbar component. This will be used when granting the template ability item later.
Verse# A utility method that gets the first fort_inventory_weapon_hotbar_component on the player. (Player : player).GetWeaponHotbarComponent()<decides><transacts> : fort_inventory_weapon_hotbar_component = first (WeaponHotbarComponent : Player.FindDescendantComponents(fort_inventory_weapon_hotbar_component)) {WeaponHotbarComponent}
Create the Base Template Ability Class
Define the base template_ability class with its required overrides. Once compiled, this class's properties are configurable when you create the item prefab.
Add the
template_abilityclass and theActiveEffectslist override.Add the
MakeContext()andMakeAbility()factory function overrides. These functions are responsible for constructing the ability context and effect when the player uses the ability.Save the Verse file.
In the Editor, select Compile Verse on the toolbar.
Create the Spicy Sprint Item Prefab
Next, build the item prefab with the Spicy Sprint ability.
In the Content Browser, select the Add (+) button, then select Entity Prefab.
In the Create Entity Prefab Definition window, select New prefab (+).
Name the prefab PF_SpicySprintItem.
Double-click the prefab to open the Prefab Editor.
In the Details panel:
Select the Add Component (+) button, search for item_component, and add it.
Select the item_component and add an entry to the Categories list.
Set the new entry to FortniteItemCategories.WeaponMelee.
Select the Add Component (+) button, search for fort_item_ability_component, and add it.
Select the fort_item_ability_component and add an entry to the ItemAbilities list.
If you want the ability to be available only when the item is equipped, you can add to the ItemEquippedAbilities list instead.
Set the value of Index[0] to template_ability, then expand Index[0].
Set the InputTrigger to Assets_input_action, then select the new dropdown and search for IA_Sprint.
Set the TargetQuery to self_ability_target_query.
Add two entries to the AbilityElements list.
Select the Index[0] dropdown and set it to fort_ability_status_effect_burn_point. This status effect does periodic health damage.
Select the Index[1] dropdown and set it to fort_ability_status_effect_pepper_point. This status effect increases movement speed.
(Optional) You can customize the StatusEffectDuration and Time of each of the status effects.
Save the prefab.
Drag the PF_SpicySprintItem prefab from the Content Browser into the Level, then save the level.
Create the Item Granter Device
Create the device that grants the Spicy Sprint item to the player at the start of the session.
Add the
template_ability_item_granter_deviceand member variable. This declares the new creative device and exposes the template ability item property so you can set it from the Details panel later.Verse# A creative device that grants the assigned item to the first player. template_ability_item_granter_device := class(creative_device): # The template ability item to grant. @editable TemplateAbilityItemEntity : entity = entity{}Add the
GrantItemTo()function. This gets the weapon hotbar and item components, then adds the item to the hotbar.Verse# Grants the TemplateAbilityItemEntity to the given player. GrantItemTo(Player : player) : void = if: WeaponHotbarComponent := Player.GetWeaponHotbarComponent[] ItemComponent := TemplateAbilityItemEntity.GetComponent[item_component] then: WeaponHotbarComponent.AddItem(TemplateAbilityItemEntity) ItemComponent.Equip()Add the
OnBegins()callback override that grants the item to the first player.Verse# When the session begins, grant the item entity to the first player. OnBegin<override>()<suspends> : void = if (FirstPlayer := GetPlayspace().GetPlayers()[0]): GrantItemTo(FirstPlayer)Save the Verse file.
In the Editor, select Compile Verse on the toolbar.
Drag the template_ability_item_granter_device from the Content Browser into the Level.
Select the device in the level.
In the Details panel, set the TemplateAbilityItemEntity to the PF_SpicySprintItem prefab instance in the level.
Save the level.
Playtest
Launch a session and playtest to verify that you Spicy Sprint when you hit Sprint. Your health ticks down at a regular rate due to the burn status effect, but your movement speed is increased from the pepper status effect.
On Your Own
Want to take this further? Here are a few ideas to explore on your own:
Use another TargetQuery option to create a reticle-targeted or area-of-effect item.
Experiment with other AbilityElements types and create an entirely different item.
Layer elements at different Time values to create interesting effect sequences.
Complete Code
using { /Fortnite.com/Abilities }
using { /Fortnite.com/Devices }
using { /Fortnite.com/Itemization }
using { /UnrealEngine.com/Abilities }
using { /UnrealEngine.com/Itemization }
using { /Verse.org/SceneGraph }
using { /Verse.org/Simulation }
# A utility method that gets the first fort_inventory_weapon_hotbar_component on the player.
(Player : player).GetWeaponHotbarComponent()<decides><transacts> : fort_inventory_weapon_hotbar_component =