Prevent item selection on open and when clicking out of bounds

Slaiz

New member
Hello,

I have two issues you may be able to help me with. Both of them are reproducible in any grid, for example in the minimalist inventory grid feature demo.

1. When opening an inventory the first item gets selected immediately. How can I change it that no item is selected by default?
2. If no item is selected and the player presses 'Space', 'Enter' or 'Left-Click' the last selected item will get selected. Even if the mouse is way out of bounds of the inventory and no matter which item was last selected (you can select the middle item and carefully use the gaps between items to 'get out' and a click outside will reselect the middle one).

I have ideas how to fix this but I'm not familiar with the codebase. I bought the UIS just recently.

Yours sincerely
 
1)
On your Display panel and binding you'll want to pay attention to those fields
1669624156043.png

Normally that should do the trick.
It does not in the minimalist inventory because the game starts with the panel open, and for some reason the InventoryGrid selects it.
But if you start with your inventory grid closed it should work.
If it does not do let me know


2)
If you want to be able to unselect UI object you'll want to remove this component from your canvas (mostly used by people that want their game to work with a controller)
1669624055995.png
 
Hello,

2) That did the trick, thank you!

1) I unchecked "Select Slot On Open" and "Remember Selected Slot" in the DisplayPanel and made sure the "Selectable On Open" is set to "None".
I also unchecked "Open On Start". After starting the game I use Smart Open in the editor to open the inventory. Unfortunately the first item gets selected still. The same thing happens in the feature demos like "1_3_Drag&Drop and Move Item" or the minimalist one.
 
You are right, it seems something else is selecting the slot on start.
After some investigating I found it was the GridBase.cs script

Add this field
Code:
[Tooltip("Select the button at index 0 on initializing the grid.")]
[SerializeField] protected bool m_SelectButtonOnInitialize = true;

And change this

Code:
/// <summary>
/// Initialize the grid.
/// </summary>
public virtual void Initialize(bool force)
{
    if (m_IsInitialized && !force) { return; }
    m_EndIndex = GridSizeCount;
    if (m_Canvas == null) { m_Canvas = GetComponentInParent<Canvas>(); }
    m_GridEventSystem.Initialize(m_GridSize);
    if (m_SelectButtonOnInitialize) {
        m_GridEventSystem.SelectButton(0);
    }

You can then untick this option
1669630433294.png

I'll add those changes in the next update
 
Top