A currency is a type of item with intrinsic value to the player. It is often used in transactional commerce, like with the vendor, and is also used when measuring a player’s wealth.
How Currency Works
Currency items work just like every other item, the key difference being that a currency item does not require a slot for storage when it is held by a player. While in a remote storage actor like a treasure chest or loot container, currency is displayed in the item form. When it transfers to the player there are special checks in place which convert it to the currency format.
When an item is added to or removed from a storage component the item’s itemType is checked to see if it is found in the component’s currencyItemTypes array. If it is found in this array and the owner of the storage component also has the AC_Inventory_Currency component (like our player controller), the item is converted to the currency format instead. If both of these conditions are not met the currency is treated like an item and stored in a slot.
Getting the Current Currency Amount
Using a reference to the AC_Inventory_Currency component (for the player this is on the player controller) you can call the getCurrency (single currency) or getCurrencies (all currencies) functions to return the current value(s).
Create a New Currency
Since currency is just another item you would add a new one to the DT_Items and make sure your ItemType is set to DA_IT_Currency. The system will handle the rest.
If you remove this included data asset for currencies, or if you want to add your own custom item type which you want to be recognized as a currency, you will need to add the reference to your data asset in the storage component’s currencyItemTypes array.
Giving Currency to a Player
Since currency is just another item you can give it to the player like you would any other item through a call to the addItem function on the player’s inventory storage component.
You can also interact with the AC_Inventory_Component directly to give currency to the player using the changeCurrency function.
Removing Currency from a Player
Since currency is just another item you can remove or take it from the player like you would any other item through a call to the removeItem function on the player’s inventory storage component.
You can also interact with the AC_Inventory_Component directly to give currency to the player using the changeCurrency function. You would provide a negative value to remove an amount.
You will want to make sure you use the get methods (mentioned above) to validate that the currency amount exists on the source if you are working directly with the changeCurrency function to perform a removal.
Customizing the Currency Window
All the widgets related to the currency system can be found in the UIs/Currency/ folder.
The player window consists of UI_PlayerCurrency.
Inside this widget UI_CurrencyList and UI_CurrencyList_Item are used by the player currency window.
For the Window Title Text, Icon, Open and Close Sounds you can customizing the variables in the Configure / Currency / Currency Window section of the AC_InventorySystem component you added to your player controller.
View the Sounds chapter to learn how to customize the other sounds.
Show all currencies instead of just earned
You can make all currencies show on the currency window instead of just the ones the player has received (default) by setting the showAllCurrencies? Boolean to true in the Currency Configuration section of the AC_InventorySystem component.
Keybinding to show currency window
See the IMC_InventoryV4_KBM_Currency input mapping context found in the Blueprints/Inputs/KeyboardMouse/ folder to change the keybinding used to open the currency window.
Currency Inventory Widget
The inventory widget can be found in the UIs/Currency/ folder.
UI_CurrencyWidget which is the widget shown on the player’s inventory.
UI_CurrencyWidget_Alert is the alert that is spawned from the currency widget when currency changes.
Change Default Currency Shown
You can change the default currency shown on the currency widget attached to the inventory using the defaultTrackedCurrency (the currency item’s row name) set in the Currency Configuration of the AC_InventorySystem component you added to your player controller.
Remove the Currency Widget
If you would like to remove the currency widget shown on the player inventory open the UIs/Storage/UI_PlayerInventory widget, select the widget from the designer tab, then just delete it.
Disable Currency System
You can disable currency by setting the EnableCurrency? boolean to false on the Currency Configuration of the AC_InventorySystem component you added to your player controller.
Keep in mind that any items that are given to the player once the system is disabled will be treated as just items, and any currency that already exists in the currency component will be unavailable.