[REQUEST] Reset item's equipped state for better reuse from ObjectPool.

WeiYiHua

Member
Third Person Controller 3.0.4.

Hello, I found that after removing the equipped item, it is still equipped state in the ObjectPool. For example, CharacterItemAction.IsEquipped.

My solution in this example is to set IsEquipped to false and call RegisterEventsWhileEquippedAndEnabled() when removing the item so that it doesn't have to check again when the item in the ObjectPool is used.

If you have a better way or other places where you can reset equipped state, please improve it, thanks!
 
Last edited:
I'm adding a check to unequip if the CharacterItemAction is Removed (returned to the pool)

Code:
/// <summary>
/// The item has been removed by the character.
/// </summary>
public virtual void Remove()
{
    if(m_IsEquipped) {
        Unequip();
    }
    for (int i = 0; i < m_AllModuleGroups.Count; i++) {
        var modules = m_AllModuleGroups[i].EnabledBaseModules;
        for (int j = 0; j < modules.Count; j++) {
            modules[j].RemoveItem();
        }
    }
Do let me know if that makes sense.
 
Doing this should work while making sure you don't mess with Unequip calls.
Also do you want to change something more fundamental? For example, change in InventoryBase. I have observed that OnUnequip and OnRemove must be called at the same time in other places to ensure that Equipped is read correctly.

CharacterIK:
1671182037351.png
 
You are right perhaps this requires a more thourough look.
I won't be able to deep dive right now, but I'll add it to the lsit of things to review.

Thank you for bringing this ot my attention
 
Top