This feature is in an experimental state so you can try it out, provide feedback, and see what we are planning. You cannot publish a project that uses Custom Inventory and Items at this time.
Please keep in mind that we do not guarantee backward compatibility for assets created at the Experimental stage, the APIs for these features are subject to change, and we may remove entire experimental features or specific functionality at our discretion. Check out the list of known issues before you start working with the feature.
This tutorial shows you how to use the Custom Inventory and Items system with Scene Graph and Verse to make a custom keycard item.
Once you build this example to learn how to create a custom keycard, you can then use a custom keycard in games involving objectives to locate and use keycards to access locked areas. Some examples include:
A locked room that contains the object for a heist
The next area in your game
Treasure or rewards for beating a boss
Before You Begin
You should be familiar with UEFN, Scene Graph, and Verse code in order to successfully complete this tutorial.
Set Up Your Project
Follow these steps to set up your project and enable Custom Inventory and Items.
Open UEFN and create a project from any island template. In Island Templates, you can use the Blank project if you want to ensure a flat area to work with. Name your new project, and click Create to open it in the editor.
From the tool bar, click Project and select Project Settings.
Scroll down to the Experimental Access section, and check the box for Inventory System. This enables Custom Inventory and Items.
Build Your Room
First you need to build the room for the example. The example is laid out like a demonstration that compares two locked doors:
The first one demonstrates how a Fortnite keycard opens a door that has a Lock device, using a Conditional Button device to determine if the player has the keycard.
The second one demonstrates how to use a custom keycard instead of the existing Fortnite keycard item, and uses Verse to determine if the player has the custom keycard.
To build the room for the example, you can use the following Fortnite assets:
Room: In the Content Browser, navigate to Fortnite > Graybox Assets > Demo. This example uses the DemoRoom assets.
Demo booth: In the Content Browser, navigate to Fortnite > Graybox Assets > Demo. Use the DemoDisplay asset.
Doors:
Door in Green Wall: Navigate to Fortnite > Galleries > Building > Tilted Towers Wall Gallery N. Find Suburban Interior Door C 02 a8a9d603 at the end of the first row.
Door in Tan Wall with Dark Trim at Top: In the same gallery as above, just to the left is Suburban Interior Door C 02 a9577d9d.
Table: Navigate to Fortnite > Props > Super. Find Academy Round Table A 13a04066.
Setting Up the Devices
Devices Needed:
1 x Player Spawner
2 x Lock device
1 x Conditional Button device
2 x Volume device
1 x Item Placer (Authority Keycard Item)
Setting Up the Door For a Fortnite Keycard
Pick one door for setting up a typical Fortnite locked door. Follow these steps to set up the devices for the first door.
Place one Lock Device on the wall next to the door. In the Details panel, customize the device options as shown below. Options not listed can be left at their default values.
Option
Value
Explanation
Visible During Game
False (Unchecked)
This hides the Lock device when the game is running, so that players won't see it.
Starts Locked
Locked
This makes the door locked when the game starts.
Hide Interaction When Locked
True (Checked)
This hides the interaction prompt when the door is locked.
Initial Door Position
Closed
This makes the default starting position for the door is Closed.
Under User Options - Functions, set the following functions for the Lock device.
You may not be able to set the Lock function until after you place the Volume device in step 3, below.
Function
Target Device
Event to Bind
Explanation
Unlock
Conditional Button
On Activated
The door is unlocked when the Conditional Button activates.
Lock
Volume
On Exit
The door is locked when the player exits the Volume for the Fortnite devices door.
Place one Volume device centered on the door itself. In the Details panel, customize the device options as shown below. Options not listed can be left at their default values.
Option
Value
Explanation
Volume Shape
Cylinder
This determines the shape of the volume.
Volume Height
0.25x
This determines how high the volume cylinder goes.
Volume Radius
0.9x
This sets the radius of the volume cylinder, which determines how close or far it is from the device location. You want the radius relatively small, so the player has to come close to the door to enter the volume.
Place the Conditional Button device next to the door, under the Lock device. Customize the options as shown below. Options not listed can be left at their default values.
Option
Value
Explanation
Key Items Required
True (Checked), 1
Check this to indicate that a key item is required to pass the condition. Enter 1 in the field to indicate that only one keycard is required.
Key Item 1
Authority Keycard (In-game name) or AGID_CP_Keycard_Agency (Item ID)
To select the item that is required, click the dropdown and search for "keycard". There are several keycard items, but this example uses the "Authority Keycard" item.
Under User Options - Functions, set the following functions for the Conditional Button device.
Function
Target Device
Event to Bind
Explanation
Activate
Volume
On Enter
When the player enters Volume for the Fortnite devices door, the Conditional Button activates. It checks if the player has the Authority Keycard.
Setting Up the Door For the Custom Keycard
For the second door, follow these steps to set up the devices.
Because the options for both Lock devices are the same, you can copy the first Lock device and paste the copy in your level. You may want to rename the device to distinguish it from the first one.
Under User Options - Functions, set the following functions for the Lock device.
You may not be able to set this function until you have placed the Player Spawner (anchor link here to that section).
Function
Target Device
Event to Bind
Explanation
Lock
Player 1 Spawn Pad
On Player Spawned
When a player spawns from Player 1 Spawn Pad, the Lock device activates and locks the door.
The options for both Volume devices are the same, so you can also copy the first Volume and paste the copy in your level. You may want to rename the device to distinguish it from the first one.
Setting Up the Table for the Keycards
Follow these steps to set up the Table with the Fortnite keycard and your custom keycard.
Place the Item Placer device on the side of the table nearest the locked door that just uses devices.
In the Details panel, customize the device options for the Item Placer as shown below.
Option
Value
Explanation
Item List
Authority Keycard
Click the + to add an array element, then click the dropdown and search for "keycard". Then select the Authority Keycard item.
Locate your custom keycard item in the Content Browser, and drag it into the level. Place the custom keycard on the table, on the side nearest the locked door set up for it.
Once you've created the keycard_gameplay_device (add anchor link here), locate the Verse device in the Content Browser, and drag it into your level.
Setting Up the Player Spawner
Lastly, you'll need to place a Player Spawner. For this example, you only need one Player Spawner. But if you build a game with multiple players, you can follow these steps to set up more. Or you can set them up differently based on your particular island experience.
Place the Player Spawner in a place where the player will immediately see the table and the two doors.
Customize the device options as shown below.
Option
Value
Explanation
Visible In Game
False (Unchecked)
For this example, the Player Spawner is invisible.
Now that you have your room and devices set up, you can create the custom keycard.
Create a Custom Item Entity Prefab
In the Content Browser, right-click to open the context menu, and select Entity Prefab Definition. This adds a new Scene Graph entity prefab to the Content Browser.
Rename the prefab Item_Keycard.
Drag an instance of the new prefab into the world by dragging it into the viewport. This makes it selectable in the Outliner.
With the Item_Keycard prefab selected, in the Details panel click +Component, and select item_component. You can scroll through the list to find it, or type "item" in the search bar to limit the results and find it more quickly.
Click +Component again, and select item_details_component. This component stores text data about the item.
The item_details component has three property fields displayed in the Details panel: Name, Description, and ShortDescription. Enter a name, a description of the item, and a short descriptive label in these fields.
Click +Component again, and select item_icon_component.
In the Details panel, expand the item_icon_component. You need to select a 2D image, which will be the image displayed in the game's UI (for example, in the player inventory) to represent the item.
Click the dropdown next to the None tile to open a context menu, and type part of the name of your image in the Search bar. In this example, we are using a PNG image named T_Icon_Keycard.png.
Select the image in the search results.
Click +Component again, and select mesh_component. For this example, select Plane.
This will add a plane mesh to your item. Depending on your settings, this plane may at first be very large. Follow these steps to resize the plane to be the size of a keycard.
In the toolbar at the top of the viewport, select the Scale tool. You can also press the R key to change to the Scale tool.
Further to the right from the Scale tool, click the dropdown for the Preset Ratio for Scale setting. Set it to 0.0625. This allows you to reduce the plane to a very small size, to represent a keycard.
Click +Component again, and select fort_item_pickup_component. Adding this component adds all the functionality of Fortnite items:
An animation for picking up an item, and an animation for dropping an item
An interaction to add an item to the inventory
A default item widget that displays when a player looks at the item
The item's mesh is disabled when an item is picked up
The item's mesh is enabled when an item is dropped
Now that you have a basic custom keycard prefab, you can create a custom Verse component that will make this item unique, so that it can be checked with Verse code to see if it opens a particular locked door.
Create a Custom Verse Component
Normally, for a large project that has a lot of Verse code files, you would want to create a new Verse file for a custom component. To do that, you would follow these steps.
Because the example for this tutorial is small, the custom keycard_item_component has been defined in the Verse file for the custom keycard_gameplay_device. See the Write the Verse Code for Gameplay section for those steps.
With your new keycard item selected, in the Details panel click +Component and select New Verse Component. The Create Verse Component window opens.
You can also create a Verse component by adding a new Verse file using Verse Explorer.
Under Choose a Template, select Scene Graph Component.
At the bottom, in the Component Name field, type keycard_item_component. Then click Create.
In the Details panel, click +Component and type "keycard" into the Search bar. You should see your new Verse component listed, so select it to add it to your custom keycard item.
In the menu bar, click Verse > Verse Explorer. Locate your new Verse component, right click it and select Open in Visual Studio Code.
Write the Verse Code for Gameplay
Because you are creating a custom item (the keycard), and you want to trigger a device when the player has the custom keycard in their inventory, you need to create a Verse device to make that happen.
In the Menu Bar, go to Verse > Verse Explorer. Verse Explorer opens in a tab next to the Outliner.
In Verse Explorer, right-click on your project name and choose Add new Verse file to project to open the Create Verse Script window.
In the Create Verse Script window under Choose a Template, click Verse Device to select it. In the Device Name field, type keycard_gameplay_device. Then click Create to create the Verse file.
In Verse Explorer, double-click your new Verse device to open the file in Visual Studio (VS) Code. Make sure all of the following are added in the top lines of code.
Verseusing { /Fortnite.com/Devices } using { /Fortnite.com/Itemization } using { /Verse.org/Simulation } using { /Verse.org/SceneGraph } using { /Verse.org/Random } using { /UnrealEngine.com/Itemization } using { /UnrealEngine.com/Temporary/Diagnostics }Next, add the code that defines your custom item component.
Verse# KEYCARD ITEM COMPONENT keycard_item_component := class(item_component) :We can add a helper function that will enable us to find the root inventory of the target agent:
Verse# Helper function that gets the first descendant inventory component from an agent. # This will be the root inventory. GetAgentInventory(Agent:agent)<decides><transacts>:inventory_component= TragetInventory := (for (I : Agent.FindDescendantComponents(inventory_component)) { I })[0]Next, define your custom Verse device as a subclass of
creative_device. Under that, set up an editable property for the Volume and Lock devices. This allows you to select a particular instance of the Volume or Lock device in the editor (important since you have two Volume devices and two Lock devices).Verse# DEVICE //// GAMEPLAY keycard_gameplay_device := class(creative_device) : # Use a volume_device to be able to check when a player approaches @editable VolumeDevice:?volume_device = false # The lock device is attached to a wall/door prop. This can be activated to lock/unlock the door it is attached to. @editable LockDevice:?lock_device = falseNow you'll use the query to see if the Volume device is present, and subscribe to the Volume device's On Agent Enters and On Agent Exits events.
Verse# Subscribe to the entry and exit events on the Volume to determine when a player/agent approaches. OnBegin<override>()<suspends>:void= if: TargetVolume := VolumeDevice? then: TargetVolume.AgentEntersEvent.Subscribe(OnAgentEntersEvent) TargetVolume.AgentExitsEvent.Subscribe(OnAgentExitsEvent)You want to check the player's inventory to see if they have the custom keycard in their inventory. This is accomplished by checking for anything with the
keycard_item_component. This code also requires that thekeycard_item_componentis present in order to open the Lock device.VerseOnAgentEntersEvent(Agent:agent):void= # Get the inventory from the player that is entering. if(TargetInventory := GetAgentInventory[Agent]): # Use a helper function to search for items in the inventory. If the return array has a length > 0, it contains the item with the required component to proceed. if(TargetInventory.FindComponentsOfType[keycard_item_component].Length > 0):Lastly, if there is more than one player present, and one player has the keycard, this code will make sure the lock stays open. But if the player with the keycard exits the volume, the Lock is closed again.
VerseOnAgentExitsEvent(Agent:agent):void= # Start by assuming that no one has the required keycard_item_component. var AgentWithKeycardInVolume:logic = false if(TargetVolume := VolumeDevice?): # Get the Agents that are inside the volume_device as an array. for(TargetAgent:TargetVolume.GetAgentsInVolume()): # Use the same check to see if any of the agents in the volume_device have a keycard_item_component.
Here is the full Verse code snippet.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Itemization }
using { /Verse.org/Simulation }
using { /Verse.org/SceneGraph }
using { /UnrealEngine.com/Itemization }
using { /UnrealEngine.com/Temporary/Diagnostics }
# KEYCARD ITEM COMPONENT
keycard_item_component := class(item_component) :