I want to execute the code written in ItemAction of the item equipped in UCC when loading save data

ymo

Member
I want to execute the code written in ItemAction of the item equipped in UCC when loading save data
 
I'm not sure what you are trying to achieve, so this might not be the best solution, let me know if you think there should be a better one.

When save data is loaded the character is cleaned from the its items and then they are added back in the correct order with the correct IDs, etc...
This is all done by the "Inventory Bridge Saver" component. It does not have an event when it finishes. I will add this to my list of things to do.

For now I would recommend creating your own "Custom Inventory Bridge Saver" by copy pasting the code. Then at the very end of the "DeserializeAndLoadSaveData" function you can call whatever Item Action you want.

Here is an example script I wrote for another user on how to get the equipped items (remember by default slot 0 is the right hand, slot 1 is the left hand.)

C#:
public class GetItemInSpecificSlot : MonoBehaviour
{
    [SerializeField] protected Inventory m_UISInventory;
    [SerializeField] protected UltimateInventorySystemBridge m_InventorySystemBridge;

    [ContextMenu("Get Right Hand Item UCC")]
    public void GetItemInSlotUCCway()
    {
        //Get the item at slot 0 (Right Hand)
        var item = m_InventorySystemBridge.GetActiveItem(0);
        
        Debug.Log("UCC: "+item);
        
        Debug.Log("Converted to UIS: "+ConvertUCCItemToUISItem(item));
    }
    
    [ContextMenu("Get Right Hand Item UIS")]
    public void GetItemInSlotUISway()
    {
        //Get the equipment item collection as an ItemSlotCollection
        var itemSlotCollection = m_UISInventory.GetItemCollection("Equipped") as ItemSlotCollection;

        //Check the item slot set to get the index
        for (int i = 0; i < itemSlotCollection.ItemSlotSet.ItemSlots.Count; i++) {
            var itemSlot = itemSlotCollection.ItemSlotSet.ItemSlots[i];

            if (itemSlot.Name == "RightHand") {
                var itemInRightHand = itemSlotCollection.GetItemAtSlot(i);
                Debug.Log("UIS: "+itemInRightHand);
                
                Debug.Log("Converted to UCC: "+ConvertUISItemToUCCItem(itemInRightHand));
            }
        }
        
        //From V1.1 you'll be able to do this,  instead of using the for loop above
        itemSlotCollection.GetItemInfoAtSlot("RightHand");
    }

    public Item ConvertUISItemToUCCItem(Opsive.UltimateInventorySystem.Core.Item uisItem)
    {
        return m_InventorySystemBridge.GetItem(uisItem, 0);
    }
    
    
    public Opsive.UltimateInventorySystem.Core.Item ConvertUCCItemToUISItem(Item uccItem)
    {
        return uccItem?.ItemIdentifier as Opsive.UltimateInventorySystem.Core.Item;
    }
}

Once you have the equipped item simply call your item action directly. Since item actions are simple classes (not Unity Objects), simply create a new instance of your item action, initialize it and call the invoke function.

Something around those lines:
C#:
var itemUser = m_InventorySystemBridge.GetComponent<ItemUser>();
var itemInfo = new ItemInfo(uisItem, 1);

var itemAction = new DebugItemAction();
itemAction.Initialize(false);
itemAction.InvokeAction(itemInfo, itemUser);
 
  • Love
Reactions: ymo
Top