I have a simple list inventory I use and I for some reason cannot get the columns and rows right I wanted it to go left to right with four columns
You can’t just increment the row and column on each item added to a grid you need to do math and divide the incoming grid item’s index by the number of columns to get the row, and modulo the index to get the column.
Here’s an example of adding things to a grid in a foreach loop from a widget I had sitting around in an old project collecting dust:
I got it though there’s a new problem if I remove multiple items it will overwrite another item
Where are you removing item from? If you have an array of items you foreach’d to add widgets to grid, and you removed item from the real array, you probably just need to dispatch an event on array change, and have the grid widget remove all children and rebuild. Otherwise, any indices used by grid will be stale and confuse the widget.
When you add an item to player, you should just call an AddItem (or whatever) function on the player’s inventory component, which should add item to its array, then after item is safely in the array, you should call an event dispatcher named InventoryChanged or something. Then in inventory widgets, edit the construct or pre-construct event. In there get player, get player inventory, then bind a new event to InventoryChanged dispatcher.
Making a dispatcher is kinda like making a function. Look for event dispatchers panel at bottom of My Blueprint panel and click teh + to add a new one. It can even have inputs like a function so you can send streings/ints/whatever across. Calling the dipatcher will essentially send a message to any other bp that has bound to it.
Widget might look something like this:
Tho if your widget already has a player var, you can just use that and get the inv comp for binding.
And yes, I’m insane and have a separate inv comp for magic.
I did that and binded my inventory changed to trigger the update and had to rework some stuff thanks. If anyone has some similar issues with uniform grid panels, I did clear the children for some reason you have to be very specific when it comes to adding stuff back, I copied and pasted my widgets add to item to list and had change how it was implemented by moving the create slot widget inside the for each loop and incremented the index. For the remove function on it equaling the get item name text I also used the grid to get child at and plugged in index to for each loop to remove child unsure if it helped but it does work so…







