Selectable Issue with Item Slot Collection View

Hello there!

I have been using ItemSlotCollectionViews for a few menus. When the menu opens up the first item slot is Selected as per the Select Slot on Open. The problem is that it is not visibly selected. If you use the arrows to navigate, it properly selects the next slots. When I double check the Event System, it is indeed selected. I noticed that if I disable Swap Item View On Assign and the slot is filled, then it does properly highlight. But if the slot is empty it will not highlight.

Video: https://streamable.com/9wht6r

Any ideas?

Thanks!
 
... I think this might be a know caveat with Unity UI. A UI Selectable component cannot be selected the same frame it is awaken (or enabled) if I remember correctly.

After looking into this in more detail, the problem comes from something else. Essetially I select the ItemView correctly, but then after it is selected the ItemViewDrawer replaces the item views. And the component that shows the selecting wasn't checking the current state of the button.

Here is the change in the SelectImageView script:

Code:
using Opsive.UltimateInventorySystem.Input;
using Opsive.UltimateInventorySystem.UI.Views;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Box UI component for changing an image when the box is selected.
/// </summary>
public class SelectImageView : ViewModule, IViewModuleSelectable
{
    [Tooltip("The image.")]
    [SerializeField] protected Image m_Image;
    [Tooltip("The default sprite.")]
    [SerializeField] protected Sprite m_Default;
    [Tooltip("The selected sprite.")]
    [SerializeField] protected Sprite m_Selected;
    /// <summary>
    /// Clear.
    /// </summary>
    public override void Clear()
    {
        var view = m_BaseView;
        if (view == null) {
            Select(false);
            return;
        }
        if (view.ViewSlot == null) {
            Select(false);
            return;
        }
        var viewSlotGameObject = view.ViewSlot.gameObject;
        var @select = EventSystemManager.GetEvenSystemFor(viewSlotGameObject).currentSelectedGameObject == viewSlotGameObject;
        Select(@select);
    }
    /// <summary>
    /// Select the box.
    /// </summary>
    /// <param name="select">select or unselect.</param>
    public void Select(bool select)
    {
        Debug.Log("IViewModuleSelectable "+select+"  "+gameObject,gameObject);
        m_Image.sprite = select ? m_Selected : m_Default;
    }
}

That should fix your problem.

I will be changing all the other classes which use a similar logic. All will be available in a future update.
THank you for bringing this issue to my attention.
 
Top