How should I go about making a "tetris" inventory?

203298-untitleduh.jpg

edit: I almost have it, I’ll post the code here when I finish it so other people can use it in the future :stuck_out_tongue:

The items in my game have a set X and Y size that they take up in the inventory, and I want the user to be able to drag and drop them, and the game to check, whether it would fit or not. I’d also like the items to have different shapes, but that’d be too complicated at the time.
I thought of using 2D arrays at first, but since they are hard to work with, especially with blueprints, I’m searching for other ways to do it.
If anyone has any tips or experience working on problems like these, please let me know, I’d be very thankful for any advice :slight_smile:

can you please share the way you did it? :]

Hi, did you finish the tetris inventory? If you have, then can you please help us out? Thank you.

There many way you could approach it one way of doing it that i got on top of my head would be integer array which you would apply 2D coordinate in index ((SizeOfY*Y)+X) and you would hold index of item in other array (i think map would be better) for reference. You would only use that grid array to check if slot is occupied, when you pick up the item form inventory you would clear indexes on previously occupied slots and assign index on new once.

The key here is checking if all slot for item placement are occupied, if at least one of them are then don’t let user to place item there, then you can just draw item on the ui using just one base anchoring coordinate, if you prevent used from placing item on occupied slot, there no way that item will be draw on top of each other.

A legit approach and it should probably work.
A bummer that UE4 doesn’t support this natively while it seems to :stuck_out_tongue: