Get UIS Item Attribute From UCC ActionModule

Zaddo

Active member
I have a weapon with a ShootableAction component. This has a custom Action Module that I need to retrieve an Item Attribute from the weapons UIS Item.

I have done this by:
1. Create a component in the UCC assembly with a property used to transfer the value. (See below)
2. Attach this component to the weapon.
3. Then use the ItemBinding component to bind the item attribute to the property
4. In the action module, I use GetComponent to retrieve this component and get the attribute value

Is this the best way to get an attribute value from an action module? It is very convoluted and I was hoping there is a more simple way.


C#:
    public class InventoryWeaponBridge : MonoBehaviour
    {
        [Tooltip("Inventory Item Durability.")]
        [ReadOnly] [SerializeField] public float m_Durability;

        public float Durability
        {
            get => m_Durability;
            set => m_Durability = value;
        }
    }
 
Last edited:
That's quite a roundabout way of getting the attribute.

The attribute is on the UIS Item. The CharacterItem ItemIndentifier is the UIS Item

So you can do this directly
Code:
public class MyCustomShootableModule : ShootableActionModule
{
    protected override void Initialize(CharacterItemAction itemAction)
    {
        base.Initialize(itemAction);
        var item = m_CharacterItemAction.CharacterItem.ItemIdentifier as Item;
        if (item.TryGetAttributeValue("Durability", out float durability)) {
            //you have durability here.
        }
    }
}

Here I do it in initialize function as an example but you can do this anytime after initialization once you have a reference to the characterItemAction.

(The code is untested so if you can't get it to work let me know)
 
That helped point me in the right direction. I knew the ItemIdentifier was the UIS Item from looking at the CharacterInventoryBridge.

The thing I didn't realise was that I can create an action module in the Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem assembly. For some reason I thought they had to be in the UCC assembly. I can now add a using for Opsive.UltimateInventorySystem.Core and cast ItemIdentifer like in your code example.

It is working :)

Thankyou :)
 
Back
Top