Item and inventory systems are a critical part of many kinds of games. You can customize Fortnite's player inventory using Scene Graph's entities and components to create items unique to your island.
Items are objects that players and agents can use and own. Inventories include the existing Fortnite player inventory, as well as any custom inventories you create with the inventory_component. Custom Items and Inventories is a system for creating, controlling, and storing items. This system is an experimental feature that you must enable in Project Settings, and use with Scene Graph and Verse in Unreal Editor for Fortnite (UEFN).
Scene Graph Basics
Scene Graph is an entity and component system, built on top of Verse. Entities are containers for components, and components give an entity functionality. You can attach entities to each other in a parent-child relationship, which creates hierarchies. A reusable arrangement of entities and components is called a prefab.
Refer to Working with Entities and Components for more information on entities and components. Refer to Prefabs and Prefab Instances for more information on prefabs.
Items
Items are created in Scene Graph by placing an item_component on an entity. Inventories treat the component like an object. The item_component supplies functionality, such as:
By itself, the item_component provides limited options to an item. Additional components create something more interesting with increased functionality.
For more information, see Item Componment.
Inventories
Inventories are containers for items and control what happens to those items. An inventory is an entity that has an inventory_component and works in the following ways:
Being aware of all the items that exist inside it.
Governing which items can enter or leave the inventory.
Determining what happens when an incoming item wants to merge with an item already inside the inventory.
Since an item may only exist inside one inventory at a time, inventories also determine the ownership of item entities. Subentities of an inventory are only considered to be items inside the inventory if they also have an item_component, otherwise they are child subentities.
By default, inventories can hold an infinite number and variety of items. With Verse you can create restrictions and rules that affect adding and removal of items. For example:
Add items to an inventory only if they have the correct category.
Limit the number of items in an inventory.
Prevent the last item from ever being removed from an inventory.
Allow items of higher priority to eject items of lower priority when the inventory is full.
Restrict an inventory to a single item.
Inventory Trees
Inventories are aware of any inventories that are beneath them in the Scene Graph hierarchy. These child inventories are known as subinventories. You can leverage the tree of inventories in many ways.
For example, you can add an item to a parent inventory where it can find its way to a more specialized child inventory. You can think of this as giving a coin to the player and having it travel through the inventory system to a wallet (Player Inventory > Backpack Inventory > Money Pouch Inventory).
To create more advanced inventory behavior, writing Verse is necessary.
Verse: Inventories
There are two ways to add an item to an inventory.
Call
AddItem()to add an item specifically to one inventory.Calling the
AddItemDistribute()function and using the inventory hierarchy to find the most suitable inventory or subinventory.
When the AddItemDistribute() function is called, the targeted inventory and all of its subinventories are given the opportunity to evaluate and claim the item. After each has been considered, the most suitable inventory attempts to add the item.
Player Inventory Root
Players have an inventory by default. This is known as the Inventory Root. Unlike other inventories, the player’s Inventory Root cannot accept items. Instead, it acts as the parent for subinventories beneath it. This provides a way for you to target the Inventory Root with AddItemDistribute() and for an item to find an eligible inventory, even if the initial target cannot receive it.
For a player to receive items, they need to have one or more subinventories beneath the Inventory Root.
The above explanation does not affect entities that have an inventory_component added through Verse or via the prefab editor.