Selecting UI button after Inventory Opens

Whenever the Inventory opens, it automatically selects the first inventory slot, which is absolutely fine, but I'm having trouble selecting another UI element that isn't part of the Inventory System (i.e., a popup of a book that appears on top of the Inventory Panel when using an item action). I have gotten it to work by checking EventSystem.currentSelectedGameObject and if it's that first inventory slot switching it, but that doesn't always seem to work and definitely feels a bit hacky.

Is there a way to either (1) prevent the Inventory Panel from selecting the first slot (note I have None in Selectable On Open in the Main Menu DisplayPanel) or (2) setting another UI button (for example with Button.Select();) after the Inventory is open? Unfortunately the script I'm using isn't a monobehavior, so I'm a bit limited.

Thanks for the help, and let me know if I can clarify anything!
 
There is a "Select Slot On Open" filed on the "Item Slot Collection Display Panel Binding" component (I believe those are the names I don't hae the project open in front of me). Disabling that should prevent the first slot from being selected.

Another thing to note button.Select() should be the correct thing to do. But I've had issues in the past where if it is called before or the same frame the button is activated it won't work. That's the just how Unity works. So you'll need to activate the button, make sure it ran Awake and Start, and only then call button.Select().

You say that the script you are using isn't a Monobehavior, is it an ItemAction? If that's the case there are some interfaces you can inherit from that will allow you to get a reference to the Display Panel or ItemViewSlotContainer where the ItemAction was called from (if it was called from the Inventory Grid).

Check this page:

I think the interfaces you might be interested by are "IActionWithPanel" and "ItemViewSlotsContainerItemAction", make sure your custom item action inherits one of them and implements the relevant function and keeps the parameter in a field variable.

Once you have a reference to one of these gameobjects you can add a custom component that references your button such that you can select it.

I hope that makes sense.
 
Thanks for all the info, this was super helpful! I have turned off Select Slot On Open in all of the Item Slot Collection Display Panel Binding components in my scene and for whatever reason ItemViewSlotForGrid(Clone) is still being selected when I open menus (even ones entirely unrelated to UIS). Is there a good way to track down what's causing this?
 
ItemViewSlots inherits the ActionButton class, you could add a Debug.Log in the Select function to know what is selecting the button.
Also, there is a component on the canvas that is used to prevent UI from beind unselected, because of keyboard/gamepad input requires a component to be selected at all times to navigate UI. Perhas you forgot to disable or remove that component?
 
Thanks so much! It was in fact the PreventSelectableDeselection component that was causing this to happen. Checking "Allow Deselection While Gameplay Panel Selected" solved the problem. It was causing a lot of issues with the New Unity Input system and getting gamepad functionality to work seamlessly with custom UI menus.
 
Top