UE5 Inventory and Item System
This page is part of the documentaiton for my UE5 Inventory and Item System

Loot System

UE5 Inventory and Item System Version: 3.0

    The loot system provides a way for you to spawn items as rewards when the player kills an enemy, or loots a treasure chests. You can also use it to spawn containers of loot, as well as make the player drop their loot.

    The functionality is added through the AC_Looting component, which you can add to your actors or your player controller.

    The AC_Looting component provides the following configuration options:

    LootSource This tells the AC_Looting component what to use as the source of loot. You have 3 options, Loot Table which uses a loot table (we go over this later in this chapter), Inventory Component which uses the items found in an inventory component on the same actor, and finally Custom Loot which lets you specify a specific list of items.
    LootDistributions This is how the AC_Looting component will handle the loot from the LootSource. You have the following options, LootThroughUI which will show the loot UI on the screen for the player. You also have the options Spawn Loot Items in the World and Spawn Loot Container in the World, which do exactly what the name suggests.
    DestroyContainerWhenEmpty? If this AC_Looting component is attached to a container this will destroy the container when it is emptied.

    There are also a number of settings based on the Loot Source you selected.

    For InventoryComponent you can provide a StashIndex.

    For LootTable you can provide the loot table to use as well as the LootTableChanceModifier which sets the minimum threshold for the dice roll which at default is between 0 and 1. With a LootTableChanceModifier of 0.5 the dice would roll between 0.5 and 1 instead, which will greatly increase the chance for more and rarer drops.

    For CustomLoot you will be able to provide an array of items to offer the player.

    How to tell the loot system it is time to drop loot …

    The AC_Looting component is just part of the equation, you have to tell this component when it is time to spawn the loot, and you do this by getting a reference to this component on your actor and then calling the HandleLoot event. The system will handle the rest based on your configuration.

    Drop Enemy Loot

    Add both the AC_Looting and the AC_Inventory components to your enemy blueprint. Then configure the loot settings of the AC_Looting component. The AC_Inventory component is needed even if you do not plan on using the Inventory Component loot source, as the AC_Inventory component is a prerequisite of the loot system.

    When it is time to spawn the loot call the HandleLoot event on the AC_Looting component you attached.

    Drop Player Loot

    For the player make sure the AC_Looting component is added to the player controller. Then use the InventoryComponent option as the source, and drop in the container as the distribution. Then you would just call HandleLoot when it is time for the player to drop their inventory. You do not need to add an AC_Inventory component to the player controller, one is added for you automatically when the AC_InventoryItemSystem does its setup process.

    If you would also like to drop the hotbar (stash index = 2) or equipment (stash index = 3) you will need to add additional AC_Looting components that are setup for each of those components. Make sure you also call HandleLoot on each component when it is time to drop the items in it. Keep in mind if you select drop as a container for each of them, multiple containers will drop.

    Currently there is no way to combine everything from multiple components into one container, this is something you would have to add if it applies to your game.

    Loot Tables

    Loot tables are used by both the loot system and the loot box item. They give you a way to establish a table of possible loots driven by a roll of the dice. By default using this will roll the dice once, and reward all possible items that meet the chance of the roll.

    If you add a lot of items to your loot table you are probably going to want to come up with a way to further randomize and limit how many total items the player can receive. That functionality is not provided in the current system, and you will need to add this logic check to the GetLootFromLootTableAdvanced function found inside the BP_SharedFunctions global blueprint function library located in the Blueprints/Variables/ folder.

    To create a loot table open the DT_LootTables located in the Blueprints/Variables/DataTables folder. Then just add a new row. Make sure to give your row a row name, this is how you will identify this loot table when setting it on the AC_Looting component.

    Then just add new items to the Rows field. Each item field asks for a ItemRowName, QuantityMin, QuantityMax and Chance. Chance is the chance to win, so 0.85 is an 85% chance (often) to win the item in a roll and 0.1 is a 10% chance (rare) to win the roll.

    Loot Boxes

    Loot boxes are actually just Usable Items. You can also override the loot table and the loot table chance modifier on loot boxes using the OverrideData of the item. Use the key loot_table with the value equal to the row name of the loot table and use the key loot_table_chance with a float value between 0 and 1 to boost the chance of receiving the best and most loot. These keys will only work if you are using the GetLootTableFromItemData function like the AC_ItemOnUse_LootBox_LootTable does.

    Treasure Chest

    The treasure chest is the default class for spawning loot inside a container and showing it through a UI window. It creates the AC_Looting components based on the settings you provide it. The Loot Container that is spawned in the world when you handle loot is a child of the treasure chest.

    The Treasure Chest blueprint BP_TreasureChest can be found in the Blueprints/Interactables/Containers/TreasureChest. Drop a copy of this in the world and configure it to your needs.

    This documentation and asset version are new. If you encounter any bugs or if anything doesn't make sense, please let me know.