Adding whole inventory on Scene start

Niroan

Member
Hello

I managed to get everything setup finally :D
But it really looks nice now!

I have setup cloud scripts and combined with online inventory.
Now i used inventory.AddItem("string", 1); but this code makes a pop up for every item i add.
I have 80 items inside my inventory. So that is 80 pop ups.

I want a code so i can add whole inventory to a specific Collection with a ForEach loop. I allready have the item names syncronized.
So i only need a way to add whole inventory on start of scene.
 
And in the same case.
I have a special UNIQUE ID from the Cloud inventory. That i would like to pass to the item when i create them in the players inventory.
So i can target that id number. When deleting and item from cloud i need to pass the ID number for deletion can happen.

Can you please help me do that?
 
I'm glad you were able to get things working.

The first issue were items pop up. It is done by the InventoryMonitor component. It is located under the game play panel normally.
1601622706938.png

You can choose to remove it completely or just enable/disable it when you want to popup items added to the inventory or not. Simply disable the entire game object just before loading the items from the cloud and set is active once all the items are added

For the second issue, you have an ID per itemDefinition or per Inventory?

If it's per item then, since you are using only Immutable items, why not use the string name or the matching ID to know what the item that needs to be removed is. Then call the the remove item function of the inventory.

If it's a unique inventory ID then you should add a new custom compoentn next to the inventory that lets you identify the game object from that ID, you can keep a Dictionary in a custom manager script <ID,Inventory>

I' looking forward to seeing the results of your work, don't hesitate to post in the WIP category of the forum
 
Nice so i just disable and enable the GameObject.
That is easy to do.

The other thing is this. When i get the Inventory from PlayFab. Then EACH item has a uniq ID. When i get the data from the cloud i can see the ID in the list for each item.

When i need to remove item from inventory, i need to add that ID for it to be removed. So i need some way to attach that ID to the item.
Can i make a custom attribute i can read and set from code? If so how?
 
2020-10-02_10h22_56.png
the Inventory from Playfab looks like this. So the Instance ID is the uniq ID that i need to use to remove specific item :)
 
Since you are using Immutable items I would recommend creating a table "item name" : "Item ID", that table could either be on the cloud or on the client. Then when you remove an item simply check the id for that item name.

There's an event for when an item is removed from an item collection. EventNames.c_Inventory_OnRemove_ItemInfo.
Make sure the check out the EventNames script which has all the event names with a little description.

You could listen to that event in a custom script, get the id from the table you created when adding the items to the inventory and then remove the item from the cloud using the id from the table.
I hope that helps :)
 
But How do i ADD value for each item?
Each stack needs to be with Unique id just like rarity i want and empty string that i Can set and get
 
Yes i allready know that :)

I have another issue now. When i use the AddItem function. And type in like 8 of the same item.
Then it adds 8 items. Is there any way to make item stackable?


C#:
public void AddItemsToInventory()
    {
        //inventoryPopUP.SetActive(false);
        Debug.Log("TESTING INVENTORY");
        foreach (var item in GTD_GameData.Playfab_InventoryItems)
        {
            Debug.Log("ItemDisplayName: " + item.ItemDisplayname);

            string ItemName = item.ItemDisplayname;
            // Find your item definition.
            Debug.Log("ItemName: " + ItemName);
 
            var myItemDefinition = InventorySystemManager.GetItemDefinition(ItemName);
            Debug.Log("ItemDefinition: " + myItemDefinition);
    
            //Create an item from that definition.
            var myItem = InventorySystemManager.CreateItem(myItemDefinition);
            Debug.Log("MyItem: " + myItem);
            Debug.Log("Item Value ItemAmount: " + item.ItemAmount);
            int Amount;

            if (item.ItemStackable)
            {
                Amount = int.Parse(item.ItemAmount);
            }
            else
            {
                Amount = 0;
            }
            
            Debug.Log("Amount: " + Amount);
            //Make your item Info, Note double (( )) the (1,myItem) is an itemAmount.
            //Note: ItemInfos can have a reference to the item stack and the itemcollection/inventory where the item comes from.
            var myItemInfo = new ItemInfo((Amount, myItem));
            Debug.Log("MyItemInfo: " + myItemInfo);
            inventory.AddItem(myItemInfo);
                  
        }
 
Its working for materials. But now on normal items.
What is the thing that makes and item stackable? Im so lost atm i think i have seen myself blind on the code.

But i have made the PlayFab integration ready. So it now goes online and gets inventory in the cloud, and converts it to Ultimate inventory System.
Works SOOO good :D!
 
I'm glad things are working!

The items only stack when they are immutable and not Unique. You can set that on the item category, make sure both are off:
1601652967650.png
 
So the inventory works like charm now. It loads from Cloud.

I only need to remove items when "Drop" is used via Action button and Craft is used and new item is Purchased via shop.
Where are those event stored?
 
You can use the item collection add and remove events.

You can find all the events in the EventNames.cs file.
 
Yes but those "events" are strings. Where are the actually events that is called?

If i write EventNames.c_Inventory_OnRemove_ItemInfo += EventRemoveItem;
I get a errors.

Normally i would just add this:
C#:
   void OnEnable()
    {
        EventManager.OnClicked += Teleport;
    }


    void OnDisable()
    {
        EventManager.OnClicked -= Teleport;
    }


    void Teleport()
    {
        Vector3 pos = transform.position;
        pos.y = Random.Range(1.0f, 3.0f);
        transform.position = pos;
    }
 
The link to the documentation I sent you above shows examples of how to register, execute and unregister events using the EventHandler.

Make sure to read the documentation carefully
 
Top