Change value of Dictionary Key-Value Pair in Blueprint

I have an ui for an inventory system, i have a container widget for each slot of my inventory, at begin play i fill a dictionnary with the slots as keys and nothing into the value.

And as for now I have this function to add a base item to my inventory.

I want to add it to the first slot that is empty. so i check if the value corresponding to the key is valid, if not it means i have room there, so i create the item and add it as child of the slot, and then i want to set it as the value coresponding to the key.

But that assignement doesnt seems to work since if i call this function several times, it always adds an item to the first slot. so the value of the key stays null.

How do you change the coresponding value of a key in a dictionnary in blueprint ? I really struggle with dictionnaries in bp in my learning process since it is not so intuitive compared to code in my opinion.

The Add Item To Slot is just a function that sets the item as child of the slot, not related to the dictionnary.

And in consequence of the problem, the printing of the index at the end always prints 0.

Thank you in advance for your further answers.




EDIT:

I made it so I don’t have to rely on a dictionnary, but still i’d really like to know what is the actual problem I encountered,

I really like using dictionnaries in general, and i couldn’t seem to find how you do that simple operation of changing the coresponding value of a key in blueprint.

hi, if your dictionary has the same key with the “Add” function it overrides, if there is not, it adds.

I hope this helps.

1 Like

Thanks man, for some reason I spent way too long trying to figure out this simple thing.