Data-Driven Inventory Screen
- 50541507
- Apr 22, 2022
- 3 min read
In order to make stuff like the Inventory Screen function properly, I need to make then data-driven, and to create the item widgets based on the items the player actually has. I will do this through Data Tables, basically CSV Spreadsheets. These then have their rows read (and because they use a Structure for their data, each row will be like a new Inventory Item) and create an Inventory Item with the same settings applied to it. I followed a tutorial here and made a mock-up of it with Payday 2 guns:
This is created through a For Each Loop which creates a Widget and sets its variables for each row in the Data Table.

One thing I want to change about this for the Inventory Items however is how the Name is stored. This example, I'm using the row's name, not a Text variable, which means I cannot have spaces in it. This is a problem for the weapons, as most have spaces, and I simply couldn't use them.
I already had the Enumerators for the weapons I needed because of making them for the Items, so all I had to do was make a Structure with all of them in, and link it up to a Data Table to use in Blueprints.

I decided to make a long Enumeration for the Weapon Type instead of having it as Text because it will eliminate any typo errors for it.

It is long and in hindsight it would be better to make a system which uses different Enumerations for each Weapon Group, but I don't know how I would create that, so this is fine. UE4 does let you search through long Enumerations like this though, so it doesn't really matter much.

Of course, changing the Text to an Enumeration means I need to change what does into setting the text component in the item, which means I need to fill out this:

Except I don't need to, because you can convert an Enum to a String, then convert that to a Text and it displays whatever option is chosen, so a Select isn't needed.
I followed the same way of creating the widgets as I did in my mock-up, but had a small "miscalculation". Since my Item buttons are set up in a different way to my mock-up, I first tried to do it the same way by just setting the components' text, brush or whatever using their functions and not setting the Item's variables. This means that any animation or component dependant on the variable being set will be set to default, leading to this:

This doesn't change the colour of the text nor the drop down menu and doesn't change the contents of the menu either because of it. So I created another function which set the variables, then called the function to set the components themselves after it. I called these both in the main Inventory Screen because I wasn't sure which would be called first, the Inventory Screen's Pre Construct, or the Item's Pre Construct. I could put the second function inside the first, so I only need to call one, but using them separately like this allows me to easily make changes if I need to, like I have for that example above. I'm writing this after completing this system. Anyway, using both functions makes them work fine like this:

Now, adding new items is as easy as making a new row in the Data Table:

And thus concludes this blog post. Actually, it doesn't. Because I also need to include the different knives, I decided I would make a simple system that changes which Enum shows depending on the choice of another Enum, specifically, if the Weapon Group Enum is Knife, then it will use a new Enum for the Knife Type instead of the Weapon Group. I could do this for each group of weapons, or why even limit myself to that? I could set everything based of the specific weapon that it is (like if a MAC-10 is chosen, it would set the Group to SMG, the Team to Terrorist, etc.). But, that would require me to essentially remake the Weapon Group Enum multiple times, which is not worth the investment, as well as the fact that having more drop down boxes is fun and reminds me of how the Source Engine does certain things. Anyway, now I added knives:

If the Weapon Group is anything but Knife, then it will use the Weapon Type instead of Knife Type. It just doesn't grey anything out because I don't think that's possible. And because it doesn't need to be intuitive as I created it and am the only one who will use it.


And now ends the blog post.



Comments