• We are looking for a content creator to help market our assets and a future unannounced project. More details are on this page.

[BUG] Hide Cannot Invoke Actions cause ArgumentOutOfRangeException

Egnech

New member
There is a bug with Hide Cannot Invoke Actions option at ItemActionPanel.
When this option is set, and item action is calling base.CanInvokeInternal() the m_ItemViewSlotsContainer is not yet assigned which cause ArgumentOutOfRangeException.

This happens because SetViewSlotsContainer() is called after CanInvoke(). The solution is to do it otherwise. Here is the code:

ItemActionPanel.cs:39
Code:
public void AssignActions(ListSlice<ItemAction> itemActions, ItemInfo itemInfo,
    ItemUser itemUser, ItemViewSlotsContainerBase itemViewSlotsContainer, int itemViewSlotIndex)
{

    m_ItemInfo = itemInfo;
    m_ItemUser = itemUser;

    m_ItemViewSlotsContainer = itemViewSlotsContainer;
    if (m_ItemActions == null) { m_ItemActions = new List<ItemAction>(); }

    m_ItemActions.Clear();
    for (int i = 0; i < itemActions.Count; i++) {
        var itemAction = itemActions[i];
       
        itemAction.Setup(itemInfo, itemUser);
        itemAction.Initialize(false);
       
        // Call SetViewSlotsContainer before CanInvoke
        if (itemAction is ItemViewSlotsContainerItemAction itemActionWithContainer) {
            itemActionWithContainer.SetViewSlotsContainer(m_ItemViewSlotsContainer, itemViewSlotIndex);
        }

        if (m_HideCannotInvokeActions) {
            if (itemAction.CanInvoke(itemInfo, itemUser) == false) {
                continue;
            }
        }
       
        m_ItemActions.Add(itemAction);

        // if (itemAction is ItemViewSlotsContainerItemAction itemActionWithContainer) {
        //     itemActionWithContainer.SetViewSlotsContainer(m_ItemViewSlotsContainer, itemViewSlotIndex);
        // }
    }

    AssignActions(m_ItemActions);
}

In case this is the correct solution, can you please include it to the future release?
 

Sangemdoko

Moderator
Staff member
Yes your fix makes sense. Thank you for sharing the code with me, I made the change in the source code.
 
Top