UIS Integration: How to soft equip item?

vodinh

Member
In the integrated demo with UIS, I cannot find anywhere to set up the rifle to display in Holster.

I tried to add a rifle to the Equippable collection, the rifle appeared in the holster but the holster was not active. As far as I know, when it is initialized, it is attached with:
if (HolsterTarget != null) { // The holster target will be enabled when the item is picked up. HolsterTarget.gameObject.SetActive(false); }

and is only activated again when the Pickup() function is called. But InventoryBase did not call:
if (slotID != -1) { var item = GetCharacterItem(itemIdentifier, slotID); if (item != null) { item.Pickup(); EventHandler.ExecuteEvent(m_GameObject, "OnInventoryPickupItem", item, amount, immediatePickup, forceEquip); if (m_OnPickupItemEvent != null) { m_OnPickupItemEvent.Invoke(item, amount, immediatePickup, forceEquip); } } }
the var item = GetCharacterItem(itemIdentifier, slotID) is null, so I don't know why.

1679499870958.png
 
This seems to be a bug.

There were 3issues:

1)
In InventoryBase.cs

At the end of the function below when the "OnItemIdentifierPickedUp" function is called I made a typo and inversed "characterItem.SlotID" and, "1". So it thought the ID was 1...

Code:
/// <summary>
/// When a character item is spawned send events to notify objects outside the inventory.
/// </summary>
/// <param name="characterItem">The character Item that was added.</param>
public virtual void OnCharacterItemSpawned(CharacterItem characterItem)
{
    if (!m_ValidCharacterItems.Contains(characterItem)) {
        m_ValidCharacterItems.Add(characterItem);
    }
    if (m_AllCharacterItems.Contains(characterItem)) {
        return;
    }
    EventHandler.ExecuteEvent(m_GameObject, "OnInventoryWillAddItem", characterItem);
    m_AllCharacterItems.Add(characterItem);
    m_CharacterItemsBySlot[characterItem.SlotID].Add(characterItem);
    // Notify those interested that an item has been added.
    EventHandler.ExecuteEvent(m_GameObject, "OnInventoryAddItem", characterItem);
    if (m_OnAddItemEvent != null) {
        m_OnAddItemEvent.Invoke(characterItem);
    }
    // The ItemIdentifier event should also be called in cases where the amount is greater than 0.
    // This allows the ItemIdentifier to be picked up before the item has been added.
    if (GetItemIdentifierAmount(characterItem.ItemIdentifier) > 0) {
        OnItemIdentifierPickedUp(characterItem.ItemIdentifier, characterItem.SlotID, 1, false, false);
    }
}

2)
In the CharacterInventoryBridge.cs

THe Item map was updated after the function to pickup was called in the base function. So it couldn't find the character item when GetCharacterItem was called (as you mentioned)

Code:
/// <summary>
/// When a character item is spawned send events to notify objects outside the inventory.
/// </summary>
/// <param name="characterItem">The character Item that was added.</param>
public override void OnCharacterItemSpawned(CharacterItem characterItem)
{
    Debug.Log("On Character item spawned "+characterItem);
    m_ItemToCharacterItemMap[characterItem.SlotID][characterItem.ItemIdentifier] = characterItem;
    base.OnCharacterItemSpawned(characterItem);
}

3)
All this made me find another bug, this time in the EventHandler. But I can't share the fix with you here because it is in a dll, you will have to wait for the next update. Thankfully the next update should be next week if all goes well.
 
Right after writing the first post I found another issue where the item would not be shown if it was removed and then added again.

In the CharacterItem.cs:

I added a SerVisibleObjectActive call ro referesh it.

Code:
/// <summary>
/// The item has been picked up by the character.
/// </summary>
public virtual void Pickup()
{
    // The item will not be started if the item is picked up at runtime.
    if (!m_Started) {
        Start();
    }
    
    // If the item is picked up again set it visible.
    SetVisibleObjectActive(false, m_Inventory.GetItemIdentifierAmount(m_ItemIdentifier) > 0, false);

Hopefully that will make it work as expected
 
Top