Hi, I am using Unity Ui Prefab for Inventory, and my inventory is only for viewing items but no using or selecting the items. And I am also using keyboard to direct control the menu. So I wish to use scripts to read the item being hovered when the inventory menu is closed, and then set the cursor to hover over that item again when the inventory menu is opened again. What scripts may I use?
I tried PlayerMenus.GetMenuWithName ("CustomInventory").selected_element but it seems to reference nothing; and PlayerMenus.GetMenuWithName ("CustomInventory").selected_slot but it is always equal to 0.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
I also hope to make it:
If the previously hovered slot is disabled (e.g. the item is gone because of the story), the cursor will go back to the first slot when the inventory menu is opened again.
The selected_slot property is specifically reserved for AC-rendered menus.
To determine which slot is currently-selected, you can try hooking into the OnMouseOverMenu custom event (which should also work with direct-navigation) to record the last-set slot index. You can then use this to select that same index in the OnMenuTurnOn event.
Something like this:
Thanks. How about if the previously hovered slot is now disabled? Any script can get the enable state of the slot?
It seems the OnMouseOverMenu is not doing anything. My inventory doesn't pause the game, and use the Engine > Manage System: Enable Control in-game menus to hover across slots. This are my settings:
https://i.imgur.com/Yr5AVfl.png
https://i.imgur.com/K2UghC6.png
https://i.imgur.com/hT4Sj5h.png
Apologies, I was mistaken - OnMouseOverMenu is indeed for mouse-only.
Since you're using Unity UI, you can instead hook into the ISelectHandler event. Replace the above script with:
Then attach the following to each Inventory UI Button, setting the "This Slot Index" value as appropriate: