# Source URL: https://dev.epicgames.com/documentation/en-us/fortnite/inventory-component-in-fortnite
# Local doc: epic-docs/documentation/en-us/fortnite/inventory-component-in-fortnite.md
# Section: Verse Example
# Copyright Epic Games, Inc. All Rights Reserved.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Itemization }
using { /Verse.org/SceneGraph }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Itemization }
# This helper function gets the first inventory component from a child entity of 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]
# This device will grant items to the player inventory when they are added.
custom_loadout_device := class(creative_device) :
# You can add item prefabs to this list to give to players.
@editable
LoadoutItems:[]subtype(entity) = array{}
OnBegin<override>()<suspends>:void =
# Subscribe to PlayerAddedEvent for players who join later.
GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAddedEvent)
# For all players presently in the simulation call Grantitems().
for(Player : GetPlayspace().GetPlayers()):
GrantItems(Player)
# If we can get the inventory root, then add each item from the LoadoutItems array.
# Use AddItemDistribute() to find a home beneath the inventory root.
GrantItems(Player:player):void =
if(PlayerInventory := Player.GetInventoryRoot[]):
for(ItemToGrant : LoadoutItems):
NewItem := MakeItem(ItemToGrant)
Verse Library
verse
02 Verse Example
Distributes a predefined loadout array of items to players when they join.
extracted-snippets/documentation/en-us/fortnite/inventory-component-in-fortnite/02-verse-example.verse
Sign in free to read the full source 🌴
This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.