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

Currency System

UE5 Inventory and Item System Version: 3.0

    With the currency system you can add multiple forms of money to your game, giving your players the opportunity to produce and grow their wealth from the items they find, produce and sell.

    By default the currency system is activated for you, and I’ve added 4 currencies to get you started: gold_coins, silver_coins, bronze_coins and diamonds.

    The inventory includes a currency widget, which can be used to toggle the currency tab, which shows all the player’s earned currencies. The player can change the currency shown on the inventory by clicking on another currency from the currency tab. The player can also drop currency in the world by holding shift and left clicking on the currency widget, or a currency from the currency tab.

    Create a new currency

    Add a new item to your DT_Items data table and set the ItemType to Currency. The currency system will take it from there and handle the rest.

    Award currency to the player…

    You have two options, you can get a reference to the currency system (one can be found through the AC_InventoryItemSystem) and call the AddCurrency event.

    Or you can use the AddInventory event you use to add other items to the player’s inventory. Whenever a currency item is added to a component owned by the player (inventory, hotbar, bank, equipment) it will convert it to the currency format automatically.

    Since currency is also an item, you can also award it to the player through treasure chests and loot like you would any other item.

    It is also possible for currency items to spawn inside of storage containers. Take for example our spoil system and the golden goose egg item. When it spoils it turns into a gold coin, a currency item. Now if our egg spoils while it is in a storage container we can’t really award the player the currency, because the storage container is something that can be used by any player. What happens is the currency appears in the inventory as an item. When it is withdrawn from the container it will be converted to a currency

    One thing to keep in mind: the bank is not actually an external storage container, and is really something that is always attached to the player. This means items put in the bank that spoil into currency like the goose egg will still award the player even if the bank is not currently open. To change the way this works so it actually produces currency items in the bank you are going to need to add another check to the currency system handler logic located inside of the ChangeInventoryBy function of the AC_Inventory component. The section I highlighted with a gold is where it converts items to currency, if you add another check to see if it is the bank before it occurs you can get around this default behavior.

    Remove currency from the player …

    For this you will need to get a reference to the currency system (the AC_Currency component on your player controller). A reference to this is also available for you through the AC_InventoryItemSystem component. Once you have the reference then you would just call RemoveCurrency.

    Get the current amount of currency a player has …

    To get the current amount owned by the player for any currency use the getCurrency function available to you through the currency system (the AC_Currency component on your player controller). A reference to this is also available for you through the AC_InventoryItemSystem component. Once you have the reference then you would just call getCurrency from it. Provide the CurrencyItemRowName and it will give you the current amount owned as a float.

    Setting the currency and price of items sold to a vendor …

    You can define what the sell currency is for each of your items on the DT_Items data table using the ItemSellCurrency and ItemSellPrice fields. Keep in mind ItemSellPrice is the base price before the vendor’s sell multiplier (which by default is 0.5).

    Showing all currencies on the currency tab and not just the ones the player has earned …

    Set the showOnlyEarnedCurrencies? boolean to false on the AC_InventoryItemSystem you attached to your player controller. This will show all possible currencies, even ones the player has not earned yet.

    Change the currency that is shown at the bottom of the inventory …

    This is something the player can do by clicking on a currency from the currency tab. If you would like to change the default one that is shown you can do this by changing the defaultCurrencyTracked variable on the AC_InventoryItemSystem attached to your player controller.

    Hide the currency widget shown on the inventory …

    This widget will not be shown if you disabled the currency system, but if you would like to use the currency system but just not show this widget you can disable it by setting the showCurrencyOnInventory? boolean to false. This variable is also found in the Currency System settings of the AC_InventoryItemSystem you attached to your player controller.

    Keep in mind if you hide this you will need to add a key binding that lets the player view their currency tab. This input action already exists for you and is called IA_Currency_ToggleUI. This input action is used by the gamepad, but it will only work if the inventory is already open.

    Disable the currency system …

    If you would like to disable the currency system, set the enableCurrencySystem? boolean on the AC_InventoryItemSystem attached to your player controller to false. You can find this variable in the Currency System section of the details panel for the component you attached. Keep in mind even with the currency system disabled currency items can still appear in your world, however when they are added to the inventory they will be destroyed without anything actually being added anywhere.

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