Hotbar Bug

fukada

Member
I created an item and set it to the hotbar.
This is because it cannot be put in the inventory.

I was able to set it, but I can't use the hotbar actions afterwards.

It seems it hasn't been initialized.
Is it a bug that it isn't initialized even though I set it on the hotbar?

What do I do to make the hotbar actions available?

public void SetCardToEmptySlot(string itemName) //最初の一つに指定カードをセット
{
// Retrieve the item definition
var itemDefinition = InventorySystemManager.GetItemDefinition(itemName);

if (itemDefinition == null){Debug.LogError("Item definition not found.");return;}

// Create a new item from the definition
var newItem = InventorySystemManager.CreateItem(itemDefinition);
if (newItem == null){Debug.LogError("Failed to create item.");return;}

var ItemInfo = new ItemInfo(1,newItem);

for (int i = 0; i < 4; i++)
{
if (IsSlotEmpty(i))
{
itemHotbar.AddItem(ItemInfo, i); // 各スロットにセットする

// アイテムアクションを更新
// itemActionBinding.RefreshItemActionsCall(ItemInfo);

break; // 最初の空きスロットにセットしたらループを終了
}
}
}
 
You must initialize the hotbar. If the hotbar never Awakes before you add stuff to it, then make sure to initialize it manually
 
Code:
itemHotbar.Initialize(false);
That should do the trick
(The false is to see initialize if you are not already initialized)
 
Sorry, please help.
Why should I have to waste hours fixing the system rather than working on the story and suffer the loss of time?

I can't control the items I set on the hotbar. No actions will start.
I tried resetting the hotbar, but there was no change and the items I set are still uncontrollable.

It seems the action thinks there is no item in the slot.
Please help.

public void SetCardToEmptySlot(string itemName) //最初の一つに指定カードをセット
{
if (EmptyCount() == 0){return; }// 空が4なら終了

var itemDefinition = InventorySystemManager.GetItemDefinition(itemName);
if (itemDefinition == null){Debug.LogError("Item definition not found.");return;}
var newItem = InventorySystemManager.CreateItem(itemDefinition);
if (newItem == null){Debug.LogError("Failed to create item.");return;}
var ItemInfo = new ItemInfo(1, newItem);

for (int i = 0; i < itemHotbar.SlotCount; i++)
{
if (IsSlotEmpty(i))
{
itemHotbar.AddItem(ItemInfo, i); // 各スロットにセットする

itemHotbar.Initialize(false);//Hotbarをリセット
itemActionBinding.Initialize(false); //Reset


break; // 最初の空きスロットにセットしたらループを終了
}
}
}
 
Last edited:
I'm sorry you are struggling with this so much.

The initialization needs to be done first, before anything.


Code:
public void SetCardToEmptySlot(string itemName) //最初の一つに指定カードをセット
{
itemHotbar.Initialize(false);//Hotbarをリセット
itemActionBinding.Initialize(false); //Reset

if (EmptyCount() == 0){return; }// 空が4なら終了

var itemDefinition = InventorySystemManager.GetItemDefinition(itemName);
if (itemDefinition == null){Debug.LogError("Item definition not found.");return;}
var newItem = InventorySystemManager.CreateItem(itemDefinition);
if (newItem == null){Debug.LogError("Failed to create item.");return;}
var ItemInfo = new ItemInfo(1, newItem);

for (int i = 0; i < itemHotbar.SlotCount; i++)
{
if (IsSlotEmpty(i))
{
itemHotbar.AddItem(ItemInfo, i); // 各スロットにセットする




break; // 最初の空きスロットにセットしたらループを終了
}
}
}


If this still doesn't work. Please send me all errors/warnings full message you are getting.

And send me some screenshots of your inspector for your hotbar.

That should help me point you in the right direction
 
The initialization was done using the script in the previous article. I don't think you've seen it.


スクリーンショット 2024-07-10 200011.png
 
Last edited:
The initialization was done using the script in the previous article. I don't think you've seen it.
The order of initialization is important. You need to initialize things before they are used, not after. If you compare your code with mine you'll see that you were adding the item to the hotbar before you initialize it, that's not the correct way.

Thank you for the screenshot. Now I see the issue.
You're missing a component for handling the input for your item hotbar, without this your hotbar won't trigger any actions.
1720685699640.png


Please make use of the feature demo scenes to see bare bones implementation of each feature. These are extremly useful to understand how things work and what are the pieces needed to ensure you get the result you want. It's also a good playground to try out different setups and see how thing work in an isolated scene
1720685800106.png

I hope that helps
 
Thank you.
I had removed "itemhotbarhandler" in order to require "SimpleInput". Thank you for pointing that out.

I created a script to handle the hotbar actions.
Currently, clicking on the hotbar works without any problems, but I'm having an issue where it doesn't work with a single click.
An error occurs when I set "itemhotbarhandler", but it may be that clicks don't respond because it's not there.


NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateInventorySystem.Input.SimpleInput.CheckInput (Opsive.Shared.Input.IPlayerInput playerInput) (at Assets/Opsive/UltimateInventorySystem/Scripts/Input/SimpleInput.cs:81)
Opsive.UltimateInventorySystem.UI.Panels.Hotbar.ItemHotbarHandler.Update () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/Hotbar/ItemHotbarHandler.cs:76)
 
Last edited:
It seems the reason you have an error when using the SimpleInput, is because it can't find the InputProvider on the Inventory gameobject.
Without an InputProvider like our "UnityInput" component, then the SimpleInput will not work.

If you don't want to use the Opsive input system then it makes sense replacing the ItemHotbar with your own thing.

As for single click, the ItemHobarHandler is only used for input, not specifically clicks.
For clicks you can use the the default way of using item actions on click:
1721632300912.png
 
Back
Top