Skip to content

Setting up inventory menu

FreemanMakesGames edited this page Aug 31, 2020 · 32 revisions

Option 1: Use FMGInvSys's implementation

FMGInvSys already provides an inventory menu implementation. Its C++ base class is UFMGInvSysInventoryMenu, and its widget blueprint subclass is WBP_FMGInvSysInventoryMenu. If you are using the provided widget blueprint as is, you can skip to the next article.

The main objective here is to use a widget blueprint that inherits from UFMGInvSysInventoryMenu. Caution and strategies are already discussed earlier. Here are some additional tips:

  1. If you are making a widget blueprint subclass of UFMGInvSysInventoryMenu from scratch, UFMGInvSysInventoryMenu has required quite a few widgets to be present, through the meta = ( BindWidget ) specifier in the UPROPERTY macro. So make sure your widget blueprint has them.
  2. Remember to specify the "Item Clicker Class" and "Item Usage Button Class" in your widget blueprint. These are 2 UPROPERTIES from UFMGInvSysInventoryMenu. For each property, the drop down menu will at least show FMGInvSys's implementation, which are prefixed by WBP_FMGInvSys...
  3. If your widget blueprint inherits directly from UFMGInvSysInventoryMenu, the functionalities you add there will only be visible in blueprint, not C++. Optionally, you can create a C++ subclass of UFMGInvSysInventoryMenu "in the middle", and add functionalities in the C++ subclass, which can be accessed both from blueprints and C++.
  4. If you make a C++ subclass of any of the FMGInvSys's C++ UI classes, you very likely need to add the "UMG" module in <YourProjectName>.Build.cs.

Option 2: Write your own C++ implementation

It is recognized that the underlying mechanics of FMGInvSys's inventory menu may not always meet a project's need. For example, it shows item usage buttons, and item description on the side, while you may want them to show at cursor position. Still, in many cases, you can just inherit from FMGInvSys's classes and add or override features. But if you do decide to write your own inventory menu from scratch, the amount of work will be much more, but hopefully not overwhelming.

Maybe the first thing you should look at is the OnItemCoresUpdated event in UFMGInvSysInventory. It's fired when an item is added or removed from the inventory, so your inventory menu should listen to it, and update the display accordingly. You'll also need to know about "item clicker", which is coded in UFMGInvSysItemClicker. In short, it's a button which also displays the item's icon. The remaining tasks are probably just adding item clickers to or remove them from various containers, and setting up UI elements like buttons and texts.

As always, studying the source code along the way should help you. You can also copy code from FMGInvSys, and make small incremental changes to it. At this point though, I don't have plan to write a complete document on how to write an inventory menu for FMGInvSys, unless the demand becomes high.