How to update hot bar when removing item via script?

ChristianWiele

Active member
Hi,

during a conversation (using Dialogue System), I exchange a weapon in the inventory (remove the old, add the new one). But if the old item has been added to the hot bar before, the hot bar still shows it after the exchange. How can I trigger an update of the hot bar in this case?

Thanks, Christian
 
By default the hotbar requires the player to manually assign and remove items from the hotbar. Even when an item is no longer in the Inventory it can still be part of the hotbar (in the demo we gray it out).
The reson we did it like this is because you might get the item back and the item will stay in the position in the hotbar where the player set it.

You can change how the Hotbar works by creating your own custom ItemViewSlotContainer, either by inheriting the Item Hotbar class or one of its base classes.

Then you can simply override the DrawInternal function to draw the hotbar the way you want. You can inspire yourself from the ItemHotbar and simply set the item view to ItemInfo.None if the amount of the item in the Inventory is 0.

To make sure the hotbar updates even when it is disabled you set the draw on enable option:
1630673203242.png

Otherwise there is also the option to override the "HandleInventoryUpdate" function (it is virtual in the ItemViewSlotsContainerBase class). That will let you know that something might have changed in the inventory you are monitoring. By default i just redraw the ItemViewSlotContainer if it is active in the hierachy. But you can change that to do whatever you want
 
Top