When using existing available character item, ItemObject.SetItem(...) is not called

airoll

Member
Hi, I'm using pre-added character items, and I noticed that in InventoryBase.SpawnItemIdentifiersCharacterItem(...), it has the following code:

C#:
if (ObjectPoolBase.GetOriginalObject(existingAvailableCharacterItem.gameObject) == characterItemPrefab.gameObject) {
    // Found an invalid character item, it can be used instead of spawning a new CharacterItem.
    foundAvailableCharacterItem = true;
    existingAvailableCharacterItem.Initialize(itemIdentifier);
    OnCharacterItemSpawned(existingAvailableCharacterItem);
}

However, if we look at CharacterItem.Initialize(...), if the character item is already initialized, then Initialize(false) will do nothing.

Therefore, I had to modify Initialize(IItemIdentifier itemIdentifier) to the following:

C#:
/// <summary>
/// Initialize with the item ItemIdentifier.
/// </summary>
/// <param name="itemIdentifier">The item identifier for this character item.</param>
public void Initialize(IItemIdentifier itemIdentifier)
{
    if (itemIdentifier == null) {
        ItemIdentifier = ItemDefinition.CreateItemIdentifier();
    } else {
        ItemDefinition = itemIdentifier.GetItemDefinition();
        ItemIdentifier = itemIdentifier;
    }

    // @CustomCode Start: The item may have already been added at runtime. If so, we still
    // want to set the item object's item.
    if (m_Initialized)
    {
        m_Inventory.OnCharacterItemStartInitializing(this);
    }
    else
    {
        Initialize(false);    
    }
    // @CustomCode End
}

OnCharacterItemStartInitializing then calls itemObject.SetItem(item). Is this the best way to fix this issue?
 
That's a great find. Thank you for letting us know. Your code is perfectly valid I'll do the same change in the source code
 
Top