Hotbar setup

Bernkastel

Member
I'm attempting to use a Hotbar that simply has references to what each item is, which one is currently being selected, and I'll have my own script deal with using the items when receiving input. My problem is that the hotbar is dynamically assigned the player inventory as the owner, but it is not showing any items that are currently in the player's inventory. I want index 0 of the player inventory to show up simultaneously in index 0 of the player hotbar, but also index 0 of the player inventory. This way the player inventory may have a 3x12 inventory display, but also a 1x12 hotbar display.

Player full inventory:
1612128729233.png

Player Hotbar:

1612128747264.png

This hotbar should have those two items in the first two slots but it does not for some reason. Is there an intended way to do this? Also what is the easiest way to get a reference to the 0-11 indexed items and which one is currently being selected by the hotbar? I'd like a separate script to listen for input and then use the currently selected hotbar slot to pass that item reference to an interactable script which determines how the item will be used. That interactable script might determine it uses up the item and remove one from the player inventory for example.
 
The default hotbar code works by letting the player choose where items should go manually, either by drag and drop or by using the item action.

If you wish to have a different functionality you will need to create a custom ItemHotbar script. A few people have done it successfully before. All you need is to inherit the Item View Slot Container Base script and override the function you want to get the functionality you want. You can inspire yourself from the ItemHotbar code too.

In the last update I added a way to get references to Item View Slot Containers anywhere in the code, Example:
Code:
var itemHotbar = InventorySystemManager.GetItemViewSlotContainer<ItemHotbar>(id, "Item Hotbar");

Once you have a reference to the hotbar (or your custom type hotbar) you can get the Item, Item Views, and Item View Slots by index. And you can do whatever you want from there.

For using items in the Hotbar, you can use Item Actions, these documentation pages should help:

If you do not like the item action system you can ignore it and use the items however you want directly in code.

I hope this helps :)
 
My initial issue with the hotbar item view not showing the items correctly is my biggest concern though. How do I have the hotbar mirror the player main inventory?
 
Sorry I wasn't clear with my earlier reply.

This is not an issue. The ItemHotbar component we created was simply not designed to mirror the player main inventory.
Instead we use ItemActions or Drag&DropActions to place items manually in the hotbar. Check the UIS Demo scene to see what I mean.

ItemHotbars differ greatly in games. We couldn't create a "one Hotbar fits all" component. So we decided to make a simple type of hotbar which users can inspire themselves from to create their own.

Therefore if our ItemHotbar component does not fit your needs you may create your own. I would recommend looking at the ItemHotbar code, duplicate it and start writing your custom ItemHotbar from there.
 
I'm attempting to set up the hotbar to work as a mirror for the first x number of items in the inventory, as described above. It would be nice if the inventory manager had this kind of hotbar in addition to the one provided but I understand not being able to meet all use cases. This asset has saved me so much time that it's not that big of a deal having to code this myself. Thanks for the resources commented above, Sangemdoko.
 
Top