AndrewSidereal
Member
I only have a few items in my game, and I'd like to always show them in the hot bar, without the player needing to set them or able to change them. Is this possible?
Thank you,
Andrew
Thank you,
Andrew
//This is about to be deprecated
itemHotbar.AssignItemToSlot( itemInfo, slotIndex );
//Instead use this.
hotbarItemViewSlotContainer.AddItem( itemInfo, slotIndex );
var player = GameObject.FindGameObjectWithTag("Player");
var inventory = player.GetComponent<Opsive.UltimateInventorySystem.Core.InventoryCollections.Inventory>();
var itemDef = InventorySystemManager.GetItemDefinition("Butterfly");
var itemInfo = inventory.GetItemInfo(itemDef);
this.ItemHotbar.AddItem(itemInfo.Value, 0);
This helped a lot actually! I was banging my head against the wall because I missed the .Value in itemInfo.Value.In case it helps anyone else:
Code:var player = GameObject.FindGameObjectWithTag("Player"); var inventory = player.GetComponent<Opsive.UltimateInventorySystem.Core.InventoryCollections.Inventory>(); var itemDef = InventorySystemManager.GetItemDefinition("Butterfly"); var itemInfo = inventory.GetItemInfo(itemDef); this.ItemHotbar.AddItem(itemInfo.Value, 0);
returns a nullable ItemInfo, because in some cases the ItemInfo might not exist. That's why you need to add the ".Value". If you need to check if the value exist first you'll need to do ".HasValue".inventory.GetItemInfo(itemDef)