Lately I’ve started working on a inventory system to familiarize myself with UMG. I decided to take water over my head and try to achieve a tetris-like inventory system. Sort of like those seen in games such as 7.62 High Caliber, S.T.A.L.K.E.R and Resident Evil and so on. Currently I’m looking for a more convenient, and more importantly - efficient way to do this. Screenshots provided are clickable for full resolution.
Question 1: Is there a way to automatically create all of these slots, or would it be easier/better to add them all manually? Currently, I have it set up like this;
I did try to automate this process, both via the Construct Event in the Widget itself as well as using Begin Play within the Character BP. None of which were successful as I can’t seem to use Add Child to Uniform Grid. No matter what I put as content; it fails*(I made a new Widget Blueprint, consisting of one image - using this as content)*. And according to UE4 Answer Hub, as of 4.7 - we can not cast to Blueprint Widgets.
The current plan is to have 14 rows and 7 columns.
Question 2: If the above is possible*(which it probably is, I just don’t know how. I do know how to use loops, though.)*, how would I go about to make hovering work for all of those slots? Can I get all the childs of the Uniform Grid and check if they’re hovered?
Because as of now, I have a very messy setup - and this is only for one row. While it works, there’s probably a hundred ways to do it, most of them being better… :rolleyes: This is my current setup;
What I’m doing here is checking if either image is hovered using the Tick Event. I then store these booleans in a Struct I made for testing purposes. I then use this struct to check if either of the slots are being hovered upon - depending on whether it’s true or false; I update their brush using a texture. This is the current outcome*(which is what I want)*;
(Above is a .gifv; if it doesn’t play - click it to view it)
While it does what I want it to. I was hoping that some kind soul out there could help me come up with a solution to automate the process slightly. The Event Graph would become a web of mystery should I repeat this for all 14 rows :rolleyes:
I know I can use for loops to achieve this, but I haven’t got the slightest clue how to add children to the grid since I can’t cast to widgets anymore.
Any help would be greatly appreciated; Whether to make it more efficient or automate the process.