Criar um keycard no Prefab Editor com itens e inventário

Este tutorial da Epic mostra como usar o sistema Custom Items and Inventory com Scene Graph e Verse para criar um item de keycard no Prefab Editor. O keycard serve a modos em que o jogador precisa achar e usar um cartão para abrir áreas trancadas — por exemplo, jogos de heist, escape rooms ou assault and extraction. Este guia resume a página oficial "Create a Keycard with the Prefab Editor" em nossas palavras, com os três scripts oficiais.
A Epic recomenda que você já esteja familiarizado com o UEFN, o Scene Graph e Verse.

Preparar o projeto
Abra o UEFN e crie um projeto a partir de qualquer template de ilha, dê um nome e clique em Create. Na barra de ferramentas, abra Project > Project Settings. Na seção Beta Access, ative Scene Graph System e Custom Items and Inventory.

A prop da porta e os devices
Você precisa de uma parede com porta que tenha um FortDoorLinkComponent. Procure no Content Browser uma wall prop com porta e arraste-a para a cena. A porta deste tutorial está em All > Fortnite > Props > Art Deco. Qualquer wall prop com Fort Door Link Component permite controlar a porta.

Lock device
O Lock device abre, fecha, tranca e destranca a porta. No Content Browser, abra All > Fortnite > Devices > Logic, arraste um Lock device para o nível e, no Outliner, arraste o device para cima da wall prop. Isso anexa o device à prop e liga a função dele à porta. O estado padrão do Lock device é Locked: a porta não abre enquanto você não mandar o device dar Unlock.

Volume device
Em seguida, um volume detecta a entrada do jogador. Aí o jogo confere se o jogador tem o item; se tiver, a porta destranca. Ao sair do volume, a porta volta a trancar, para outro jogador sem o item não passar. Arraste um Volume device da pasta Logic e coloque-o na frente da porta, de modo que o jogador entre no volume antes de chegar nela.

Criar o prefab Item_Keycard
Com a porta e os devices no lugar, crie o keycard: um prefab, alguns components e, depois, components personalizados em Verse. No Content Browser, clique com o botão direito e escolha Entity Prefab Definition > New Prefab. Renomeie o prefab para Item_Keycard e dê um clique duplo no thumbnail para abrir o Prefab Editor.

description_component
O description_component traz o texto que o jogador vê ao olhar o item. Selecione a entity-base Item_Keycard no Outliner do Prefab Editor, clique em +Component no Details, escolha description_component (você pode filtrar digitando "description") e preencha os campos.
icon_component
O icon_component mostra uma imagem no HUD. Com a entity-base selecionada, adicione o component e escolha uma textura no campo Icon. A textura da figura oficial está em All > Fortnite > Textures > Icons > 128x128. Com isso, o item já tem representação 2D: texto e ícone.
mesh_component
O mesh_component representa o keycard no mundo 3D — para o item ser visto no nível e ter um corpo com o qual interagir. Adicione um mesh_component, escolha Plane no submenu e ajuste a Scale no transform_component. O tamanho sugerido pela Epic é (X=0.400000, Y=0.400000, Z=0.400000).
Ainda falta um item_component para o prefab se comportar como item, e um jeito de entrar no inventário do jogador. Isso se faz com components personalizados em Verse. Veja também Itens e inventários no Scene Graph.
Um item_component personalizado
Comece por uma classe item_component própria, para diferenciar o Item_Keycard de outras entities. No menu, abra Verse > Verse Explorer. Clique com o botão direito na pasta Content, escolha Create New Verse File, selecione o template Verse Class, nomeie a classe keycard_item_component e clique em Create Empty. Abra o arquivo no Visual Studio Code, cole o código oficial abaixo (módulos de Custom Items and Inventory e de Scene Graph, mais a definição do component) e clique em Compile Verse. Depois, adicione o keycard_item_component ao prefab. Com isso, inventários passam a poder guardar e controlar o prefab: o sistema passa a tratar a entity como Item.
# Copyright Epic Games, Inc. All Rights Reserved.
using { /Verse.org/SceneGraph }
using { /UnrealEngine.com/Itemization }
keycard_item_component := class(item_component) :
Um component para pegar o item
O keycard já é um Item, mas ainda precisa entrar no inventário do jogador. A Epic faz isso por uma subclasse de basic_interactable_component: o component torna o item interativo, confere se o agente que interagiu tem um inventário e, se tiver, adiciona o keycard a ele.
No Verse Explorer, crie outro arquivo Verse Class com o nome item_pickup_interactable_component, cole o código oficial, compile e acrescente o component ao Item_Keycard pelo menu +Component. Salve o prefab, arraste uma instância para o nível e clique em Launch Session. Interaja com o keycard: o ícone deve aparecer na hotbar; no inventário (backpack), você vê o nome e a descrição.
# Copyright Epic Games, Inc. All Rights Reserved.
using { /Verse.org/Presentation }
using { /Verse.org/Simulation }
using { /Verse.org/SceneGraph }
using { /UnrealEngine.com/Itemization }
# Place this component onto an entity to allow it to be added to an agent inventory on interaction.
# The owning entity must have an item_component and a mesh_component.
# This component expects the interacting agent to have a subentity with an inventory_component.
item_pickup_interactable_component := class(basic_interactable_component) :
# Subscription to SucceededEvent which tracks when the interaction has occurred.
var SucceededSubscription<private> : ?cancelable = false
# If the owning entity has an item_component, and is in an inventory, then the component is interaction disabled.
# However if the owning entity is in an inventory, or does not have an item_component, then the interaction is enabled.
OnAddedToScene<override>():void =
(super:)OnAddedToScene()
if(ItemComponent := Entity.GetComponent[item_component]):
if(ItemComponent.GetParentInventory[]):
DisableItemInteraction()
else:
EnableItemInteraction()
# Always disable the interaction when the component is removed from the scene.
OnRemovingFromScene<override>():void =
(super:)OnRemovingFromScene()
DisableItemInteraction()
# Enable this component and set a new subscription if one is needed.
EnableItemInteraction<protected>():void =
Enable()
if(not SucceededSubscription?):
set SucceededSubscription = option{SucceededEvent.Subscribe(OnInteractionSucceeded)}
# Disable this component, cancel the subscription and clear the cancelable variable.
DisableItemInteraction<protected>():void =
Disable()
if(SucceededSubscription?):
if(SucceededSubscription?.Cancel()):
set SucceededSubscription = false
# When an agent interacts with the owning entity, attempt to pick up the item with the AddItemDistribute() method.
OnInteractionSucceeded<protected>(Agent:agent):void =
if(PickupInventory := GetInteractorInventory[Agent]):
if(PickupInventory.AddItemDistribute(Entity).GetSuccess[]):
# Overridable method for getting an inventory root.
GetInteractorInventory<public>(Agent:agent)<transacts><decides>:inventory_component =
Inventory := (for (I : Agent.FindDescendantComponents(inventory_component)){ I })[0]

O device que abre a porta
Você já tem um prefab que é item, pode ser pego e fica no inventário, com representação 2D e 3D. Falta um device que confira se o jogador tem o Item_Keycard e abra a porta. Crie um Verse Class chamado keycard_device, cole o script oficial e compile. O device aparece no Content Browser; arraste-o para o nível e, no Details, ligue os campos @editable VolumeDevice e LockDevice aos dois devices que você posicionou.
# Copyright Epic Games, Inc. All Rights Reserved.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/SceneGraph }
using { /UnrealEngine.com/Itemization }
using { /Verse.org/Presentation }
# Helper function that gets the first descendant inventory component from an agent.
# This will be the root inventory.
(Agent:agent).GetInventoryRoot()<transacts><decides>:inventory_component =
for (Child : Agent.GetEntities(), InventoryComponent := Child.GetComponent[inventory_component]){InventoryComponent}[0]
# DEVICE //// GAMEPLAY
keycard_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 = false
# 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)
OnAgentEntersEvent(Agent:agent):void =
# Get the inventory from the player that is entering.
if(TargetInventory := Agent.GetInventoryRoot[]):
# If the array returned from FindItems() has a length > 0, it contains an item with the required component.
if(TargetInventory.FindItems(keycard_item_component).Length > 0):
# If there is a valid lock_device, then this opens the door.
if(TargetDoorLock := LockDevice?):
TargetDoorLock.Open(Agent)
OnAgentExitsEvent(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.
for(Item : TargetAgent.GetInventoryRoot[].FindItems(keycard_item_component)):
set AgentWithKeycardInVolume = true
# If no agents in the volume have the keycard, close the door using the lock_device.
if:
AgentWithKeycardInVolume = false
TargetDoorLock := LockDevice?
then:
TargetDoorLock.Close(Agent)

O script se inscreve em AgentEntersEvent e AgentExitsEvent do volume. Na entrada, se FindItems(keycard_item_component) no inventário raiz do agente devolver pelo menos um item, o Lock device dá Open. Na saída, o device percorre os agentes que ainda estão no volume; se ninguém tiver o keycard, chama Close.
Testar o keycard
O exemplo da porta trancada e do keycard está completo. Clique em Launch Session e experimente: pegue o keycard, entre no volume na frente da porta e veja a porta abrir; saia do volume e a porta deve fechar de novo.
Para continuar
Fonte oficial e créditos
Esta página é uma explicação própria, em português, feita pela Octopus Gamers a partir da documentação oficial (Epic Games). Não é tradução oficial. Para o texto original em inglês, consulte:
Imagens: capturas da documentação oficial da Epic Games, com link para a página de origem em cada legenda. Unreal Editor for Fortnite, UEFN, Fortnite e Verse são marcas da Epic Games. Conteúdo conferido com a documentação oficial em 05/12/2026.