[Issue] Equipping another item to a slot seems to copy the stats from the previous item over

WhippedButter

New member
Hi Guys.

So I'm using my own Weapon Template Shell as a Usable Item Prefab which will take in the Item Attributes from the Item Database, then send the values to my own Item List.

When using Smart Exchange Drag and Drop or Equip Item Action, It looks like the item attributes start to blend into each other? I've attached a video file below.
So essentially what I have in my item attribute list is a projectile prefab gameobject for the fireball staff which is essentially a fireball gameobject that flings out during an attack. When equipping another item to the same slot, the Projectile Prefab appears to stay as the fireball for a weapon that has a different gameobject assignment. What will also sometimes happen is that the previous item's attributes will copy into the next item's attributes overriding it.

EI. if my current weapon is the fireball staff, if I equip an ice sword with ice damage on it, it'll inherit all of the values of the fireball staff and lose it's ice damage, and when I unequip the ice sword, it'll stay as the fireball staff. The ice sword that had it's attributes mixed with the fireball staff will auto correct itself if I find another ice sword allowing me to equip the correct ice sword stats to my weapon template.

In the video, projectile 4 is the fireball where as the default projectile prefab for all weapons is the weaponblank for ease of view.

 
Just to be sure, you have a lot of Item Attributes. These can change at runtime is that what you want? If not set all Attributes that should be immutable to the ItemDefinition Attributes.

What are you doing in terms of setting the item Attribute to your own values? Are you using the ItemBinding component or something custom?

The way the ItemBinding works:
1) When the ItemObject Item is set the ITemBinding will Bind all the Attribute values using the item value as priotiy
2) When the attribute or the value is set, just the bind property is set, not the Item Attribute. But Getting the ItemAttribute will redirect towards the property.
3) When the ItemObject is removed the ItemAttributes are set to the current property value.

My guess is that something is getting crossed when replacing an existing item.


After looking in the code I think I found the issue. Please replace this function in the ItemBinding script:

Code:
/// <summary>
/// Set the item.
/// </summary>
/// <param name="item">The item.</param>
private void SetItem(Item item)
{
    if (m_Item == item) { return; }
    if (m_ItemCategory == null) {
        Debug.LogError($"Error: A category must be specified on the Item Binding {name}.", this);
        return;
    }
    
    // Always unbind attributes.
    UnbindAttributes();
    
    m_Item = item;
    if (m_Item == null || m_Item.IsInitialized == false) {
        m_Item = null;
        return;
    }
    if (m_ItemCategory.InherentlyContains(item) == false) {
        Debug.LogWarning($"The item specified ({item}) does not match item category that was set on the binding ({m_ItemCategory}).")
        m_Item = null;
        return;
    }
    var allAttributesCount = m_Item.GetAttributeCount();
    for (int i = 0; i < allAttributesCount; i++) {
        var attribute = m_Item.GetAttributeAt(i, true, true);
        BindAttribute(attribute);
    }
}

Essentially I force to unbind all attributes before binding the new ones. I hope that is it
 
Hi Sangemdoko,

Thanks for getting back to me. I'll try moving these item stat attributes to the item definitions side as they are not suppose to change during runtime. I am coming across a whole new problem unfortunately and that appears to be an error in regards to an item attribute no longer populating from the Item Definitions Manager tab after swapping the weapons. The "Suffix" attribute which is a string no longer populates on the item that was swapped out.

EDIT: So I went ahead and just removed ALL of the item stats and it looks like it cleared.

It appears that the fireball no longer transfers to the other item but I'll keep in touch. I went ahead and moved all of my item stats to my own scriptable objects table for prefix and suffixes so they are all fields declared uniformly and this should cut down on all of the attributes that would be in the items definition manager.

So essentially my goal with the inventory system was to have diablo/path of exile style itemization where things such as elemental resistances as well as character stat bonuses could roll on an item;

example a

Vigorous Axe of the Polar Bear would roll with +20 Vigor, +20 Strength, +15 Cold Resist).

or a

FireBall Sword of the Druid would roll with a chance to shoot a fireball and +15 Nature Resist, +10 Intelligence, +15 Spirit.

So I tried to declare all of those stat fields in the Item Attributes List so I could take advantage of UIS's ability to pool all of those attributes together but it appears there seems to be issues when doing this.
 

Attachments

  • InventoryError.jpg
    InventoryError.jpg
    482.4 KB · Views: 6
Last edited:
It seems I didn't check if the value was null.
Could you try this instead?

Code:
if (!EqualityComparer<T>.Default.Equals(bindingValue, newValue)){
    SetOverrideValue(bindingValue);
}
 
It seems I didn't check if the value was null.
Could you try this instead?

Code:
if (!EqualityComparer<T>.Default.Equals(bindingValue, newValue)){
    SetOverrideValue(bindingValue);
}

Are we still in the SetItem method for this or is this placed somewhere else?

EDIT: Nevermind apparently I wasn't thinking. I went ahead and slotted this code in at line 359 in the Attribute Class. No issues at the moment.
 
Last edited:
Top