Hotbar Item Actions not working after update

Going through the process of updating to 1.1.3 (from 1.1.1), and everything went pretty smoothly, however, I'm having trouble with the hotbar. I went through the instructions on the 1.1.2 update to adjust the hotbar and I am able to assign items to it with no problem. I'm currently having two separate issues:

  1. When hitting the number key (or clicking) to perform the ItemAction, nothing happens. I've fooled around with it for a while and am having no luck. Any ideas? Here are a few of screenshots of my setup:
  2. I wrote a custom script to save the hotbar and also highlight the active item until another is selected. The save/load portion is working fine, but the highlighting isn't doing anything at all anymore. I'm wondering if this has to do with the hotbar now inheriting the ItemViewSlotsContainer, but that doesn't really make sense. I'm guessing it has to do with this line somehow, but all the code is below:
Code:
HotBarItemViewSlotContainer.ItemViewSlots[slotNumber].transform.GetChild(0).GetComponent<Image>().sprite = highlightedSlotBackground;

Code:
using System.Collections;
using System.Collections.Generic;
using Opsive.UltimateInventorySystem.UI.Item;
using Opsive.UltimateInventorySystem.UI.Item.ItemViewModules;
using UnityEngine;
using UnityEngine.UI;
using PixelCrushers;
using Opsive.UltimateInventorySystem.Core;
using Opsive.UltimateInventorySystem.Core.InventoryCollections;
using Opsive.UltimateInventorySystem.UI.Panels.Hotbar;

public class HotbarExtensions : MonoBehaviour
{
    [SerializeField] private ItemHotbar hotbar;
    [SerializeField] private ItemViewSlotsContainer HotBarItemViewSlotContainer;
    [SerializeField] private Sprite defaultSlotBackground;
    [SerializeField] private Sprite highlightedSlotBackground;

    private List<string> hotbarItems = new List<string>();

    private int currentlySelected = -1;

    private KeyCode[] keyCodes = {
         KeyCode.Alpha1,
         KeyCode.Alpha2,
         KeyCode.Alpha3,
         KeyCode.Alpha4,
         KeyCode.Alpha5,
         KeyCode.Alpha6,
         KeyCode.Alpha7,
         KeyCode.Alpha8,
         KeyCode.Alpha9,
     };

    private void Awake()
    {
        SaveSystem.saveDataApplied += OnSaveDataApplied;
        EventHandler.ScenePortalTriggered += SaveBeforeChangingScenes;
        HotBarItemViewSlotContainer.OnItemViewSlotClicked += HandleItemViewSlotClicked;
    }

    void OnSaveDataApplied()
    {
        if (ES3.KeyExists("hotbarItems"))
        {
            hotbarItems = ES3.Load<List<string>>("hotbarItems");
            LoadHotbar();
        }
    }

    void SaveBeforeChangingScenes()
    {
        SaveHotbar();
        ES3.Save("hotbarItems", hotbarItems);
    }

    void OnApplicationQuit()
    {
        SaveHotbar();
        ES3.Save("hotbarItems", hotbarItems);
    }

    private void OnDestroy()
    {
        SaveSystem.saveDataApplied -= OnSaveDataApplied;
        EventHandler.ScenePortalTriggered -= SaveBeforeChangingScenes;
        HotBarItemViewSlotContainer.OnItemViewSlotClicked -= HandleItemViewSlotClicked;
    }


    private void HandleItemViewSlotClicked(ItemViewSlotEventData slotEventData)
    {
        if (slotEventData.ItemViewSlot.Index == currentlySelected)
        {
            slotEventData.ItemViewSlot.transform.GetChild(0).GetComponent<HotbarItemView>().m_Default = defaultSlotBackground;
            currentlySelected = -1;
        }
        else
        {
            if (currentlySelected != -1)
            {
                HotBarItemViewSlotContainer.ItemViewSlots[currentlySelected].transform.GetChild(0).GetComponent<Image>().sprite = defaultSlotBackground;
            }
            slotEventData.ItemViewSlot.transform.GetChild(0).GetComponent<HotbarItemView>().m_Default = highlightedSlotBackground;
            currentlySelected = slotEventData.ItemViewSlot.Index;
        }
    }

    private void UpdateSelectedItem(int slotNumber)
    {
        if (slotNumber == currentlySelected)
        {
            HotBarItemViewSlotContainer.ItemViewSlots[currentlySelected].transform.GetChild(0).GetComponent<Image>().sprite = defaultSlotBackground;
            currentlySelected = -1;
        }
        else if(currentlySelected == -1)
        {
            HotBarItemViewSlotContainer.ItemViewSlots[slotNumber].transform.GetChild(0).GetComponent<Image>().sprite = highlightedSlotBackground;
            currentlySelected = slotNumber;
        }
        else
        {
            foreach(var slot in HotBarItemViewSlotContainer.ItemViewSlots)
            {
                slot.transform.GetChild(0).GetComponent<Image>().sprite = defaultSlotBackground;
            }
            
            HotBarItemViewSlotContainer.ItemViewSlots[slotNumber].transform.GetChild(0).GetComponent<Image>().sprite = highlightedSlotBackground;
            currentlySelected = slotNumber;
        }
    }

    private void SaveHotbar()
    {
        hotbarItems.Clear();

        foreach (var itemSlot in HotBarItemViewSlotContainer.ItemViewSlots)
        {
            if (itemSlot.ItemInfo.Item != null)
            {
                hotbarItems.Add(itemSlot.ItemInfo.Item.name);
            }
        }
    }

    private void LoadHotbar()
    {
        for (int i = 0; i < hotbarItems.Count; i++)
        {
            var tempItem = InventorySystemManager.CreateItem(hotbarItems[i]);
            var retrievedItemInfo = Statics.player.transform.GetComponent<Inventory>().GetItemInfo(tempItem);
            hotbar.ToggleAssignItemToSlot((Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo)retrievedItemInfo, i);
        }
    }

    private void Update()
    {
        for (int i = 0; i < keyCodes.Length; i++)
        {
            if (Input.GetKeyDown(keyCodes[i]))
            {
                int numberPressed = i;
                UpdateSelectedItem(numberPressed);
                Debug.Log(numberPressed);
            }
        }
    }
}
 
just to be sure you aren't getting any errors or warnings right?

1) I'm not quite sure why the input isn't working everything seems to be setup correctly...
Since you are already checking the input in a update function to update the selected item, ou might as well trigger the ItemAction from there as well instead of using the Inventory Input component.
It might also help to debug what is happening.

So remove all the "HotbarInput" from the Inventory Input component and then add this line of code in under you UpdateSelectItem call within the update function.

Code:
hotbar.UseItem(numberPressed);

Also just to be sure, you are using an Action Panel in your hotbar action, usually most people prefer hotbar actions to trigger automatically without having to select which action will be used.
If that's what you want you can remove the ItemActionPanel and instead use the action Index (-1 means trigger all Actions.)

Feel free to use the DebugItemAction to try and figure out if the action is never triggered or if the problem comes from within your item actions.

2) Your code changes the background of the ItemViewSlot Image. My suspicion is that your ItemView (not the slot) also has a background and it draws over the ItemViewSlot background so you cannot see it.
Your slot image might even be disabled since you ItemViewDrawer seems to have the option to disable the slot image ticked:
1609927872173.png

So you could either untick that and remove the background of your ItemView OR change the background of your ItemView.

I usually use the slot Image just to see the slots in edit mode (since I don't have ItemViews in edit mode usually) but then in play mode I make all the visual things on the ItemView, but that is up to you.
 
I was able to get the number keys working, but clicking on the hotbar does nothing. Is there a setting for that somewhere?

Edit: Ignore the below - I was able to get it working... somehow. I think I ended up getting it working by setting the Action Panel field of Item View Slots Container Category Item action Set Binding to "None".

=================================
Regarding the first question, I haven't been able to get anywhere with getting user input (keyboard or click) working. There are no console errors.

Some additional notes:
  • Removing the Hotbar Input from the Inventory Input component on the player and adding hotbar.UseItem(numberPressed) to my script doesn't do anything.
  • Item actions (including my custom ones) work fine when selected from the action panel when in the inventory.
  • Removed the Action Panel from the hotbar (wasn't using it anyway).
  • Debug Item Action didn't show anything in the console, so somehow, I think that the input is never making its way to the hotbar.
  • Here is a screenshot of the Item Hotbar Panel in case there is a setting I'm missing there: https://ibb.co/rt8JqmR
    • Note that I don't have the hotbar set to open on start as I open it manually after the scene loads (it was showing overtop of my black fade in when I load the game. Though checking that box doesn't fix anything.
  • A screengrab of my Hotbar Extensions component (in case anything is weird there): https://ibb.co/HVvgndx
Any other ideas to try?
 
Last edited:
I'm glad you got it working.

For clicking to use the item action, you already have set it up to do so normally:
1610007740535.png

I'm wondering if the whole thing wasn't working as expected because you weren't initializing the hotbar correctly.
Can you double check that your Hotbar is linked to the panel binding:
1610007901426.png
 
Edit: Figured it out. The image on the Item View Slot had Raycast Target turned off. Not sure if that was by default or not.


===================================
It appears that I can click the number on the hotbar and have it work, but no where in the image itself...


Here are some images of the button itself:
 
Last edited:
Top