Hotbar action by button

Grober

New member
Hello,

When im trying to use item by hotkey in hotbar there is error.
It only happens when i do it by button binding.


"
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateInventorySystem.UI.Panels.ItemViewSlotContainers.ItemViewSlotsContainerItemActionBindingBase.TriggerItemAction (System.Int32 slotIndex) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ItemViewSlotContainers/ItemViewSlotsContainerItemActionBindingBase.cs:154)
Opsive.UltimateInventorySystem.UI.Panels.Hotbar.ItemHotbar.UseItem (System.Int32 itemSlotIndex) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/Hotbar/ItemHotbar.cs:92)
Opsive.UltimateInventorySystem.UI.Panels.Hotbar.ItemHotbarHandler.Update () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/Hotbar/ItemHotbarHandler.cs:77)
"
 
I checked the code and it would seem your ItemViewSlotsContainerCategoryItemActionSetBinding component is missing a reference to the ItemHotbar. Normally this should be automatically set if they are on the same gameobject.

Here I changed the code in the ItemHotbar to make sure they bind toghether:
Code:
/// <summary>
/// Initialize before setting the inventory.
/// </summary>
protected override void OnInitializeBeforeSettingInventory()
{
    base.OnInitializeBeforeSettingInventory();
    if (m_ItemActionsBinding == null) {
        m_ItemActionsBinding = GetComponent<ItemViewSlotsContainerItemActionBindingBase>();
        if (m_ItemActionsBinding == null) {
            Debug.LogError($"The item hotbar '{name}' is missing an item view slots container item action binding", gameObject);
            return;
        } else {
            if (m_ItemActionsBinding.ItemViewSlotsContainer != this) {
                m_ItemActionsBinding.BindItemViewSlotContainer(this);
            }
        }
    }
}

You can have a look at the "6 ItemHotbar" feature scene to view an example of how a hotbar can be setup, and you'll see that it works with the button input as expected
 
It did not fix it:(
In 6 ItemHotbar it works just fine, i was trying to compere with it but was unable to find differences.


1643053679618.png
public void TriggerItemAction(int slotIndex)
{
Debug.Log("Trigger Item Action :");
Debug.Log(m_ItemViewSlotsContainer);
Debug.Log(" | Slot : ");
Debug.Log(m_ItemViewSlotsContainer.GetSelectedSlot());

var slotCount = m_ItemViewSlotsContainer.GetItemViewSlotCount();
if (slotIndex < 0 && slotIndex >= slotCount || slotIndex >= m_ItemViewSlotsContainer.ItemViewSlots.Count) {
Debug.LogWarning("The slot index you are trying to use is out of range " + slotIndex + " / " + slotCount);
return;
}

TriggerItemAction(m_ItemViewSlotsContainer.ItemViewSlots[slotIndex]);
}
Looks like its unable to find SlotContainer
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateInventorySystem.UI.Panels.ItemViewSlotContainers.ItemViewSlotsContainerItemActionBindingBase.TriggerItemAction (System.Int32 slotIndex) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ItemViewSlotContainers/ItemViewSlotsContainerItemActionBindingBase.cs:156)
Opsive.UltimateInventorySystem.UI.Panels.Hotbar.ItemHotbar.UseItem (System.Int32 itemSlotIndex) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/Hotbar/ItemHotbar.cs:104)
Opsive.UltimateInventorySystem.UI.Panels.Hotbar.ItemHotbarHandler.Update () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/Hotbar/ItemHotbarHandler.cs:77)


1643053478536.png
 

Attachments

  • 1643053022909.png
    1643053022909.png
    402.1 KB · Views: 6
Do you have an Inventory bound to the itemHotbar? Can you add items to the hotbar?
Try adding a debug statement in the "BindItemViewSlotContainer" function of the ItemActionBinding component.

Either it never happens in which case something is wrong with how your item hotbar is being initialized, or the binding gets removed after being bound correctly in which case the debug log will help us see what happens.

In the first case I would look at the ItemHotbar Panel and the DisplayPanelManager, to make sure your panel is correctly bound to the player Inventory, you can either use the Inventory Identifier ID, or drag and drop the Inventory reference directly in the inspector

I hope we get to the bottom of this.
 
Do you have an Inventory bound to the itemHotbar? Can you add items to the hotbar?
no it bounds it self, and it does it correctly
Can you add items to the hotbar?
Yes and when i click by mouse they properly evoke actions


I did start debuging ItemActionBinding like you sayd but it never goes into it, errror is somewhere before, it looks like it might be in ItemViewSlotsContainerItemActionBindingBase


Here is debug when i evoke hotbar by mouse click

1643135569752.png


And here is when i do it by keypress
1643135668700.png


public void TriggerItemAction()
{
Debug.Log("1Trigger Item Action : " + m_ItemViewSlotsContainer + " | Slot : " + m_ItemViewSlotsContainer.GetSelectedSlot());
TriggerItemAction(m_ItemViewSlotsContainer.GetSelectedSlot());
}

/// <summary>
/// Trigger the item action on the slot of the index provided.
/// </summary>
/// <param name="slotIndex">The item slot index.</param>
public void TriggerItemAction(int slotIndex)
{
Debug.Log("2Trigger Item Action :");
Debug.Log(m_ItemViewSlotsContainer);
Debug.Log(" | Slot : ");
Debug.Log(m_ItemViewSlotsContainer.GetSelectedSlot());

var slotCount = m_ItemViewSlotsContainer.GetItemViewSlotCount();
if (slotIndex < 0 && slotIndex >= slotCount || slotIndex >= m_ItemViewSlotsContainer.ItemViewSlots.Count) {
Debug.LogWarning("The slot index you are trying to use is out of range " + slotIndex + " / " + slotCount);
return;
}

TriggerItemAction(m_ItemViewSlotsContainer.ItemViewSlots[slotIndex]);
}

/// <summary>
/// Trigger the item action of the item view slot.
/// </summary>
/// <param name="itemViewSlot">The item view slot.</param>
public void TriggerItemAction(ItemViewSlot itemViewSlot)
{
Debug.Log("3Trigger Item Action : " + m_ItemViewSlotsContainer + " | Slot : " + m_ItemViewSlotsContainer.GetSelectedSlot());

if (itemViewSlot == null) { return; }

if (m_ActionPanel != null) {
OpenItemAction(itemViewSlot.ItemInfo, itemViewSlot.Index);
return;
}

if (m_UseItemActionIndex == -1) {
UseAllItemActions(itemViewSlot.Index);
} else {
UseItemAction(itemViewSlot.Index, m_UseItemActionIndex);
}
}
 
Well that makes no sense. In you first case m_ItemViewSlotsContainer is not null but in the second it is...

I'm wondering if you aren't mistakenly referencing a completely unrelated ItemViewSlotsContainerCategoryItemActionBinding. Perhaps you are referencing that component on another gameobject or prefab.

Set both the Item Actions Binding field and Item Hotbar handler to Null and then assign them again, make sure to save your scene:
1643189577529.png
 
Top