Role Analysis Project 2 (New Engine Experimentation): Unreal Engine Inventory System with Blueprints

Published April 01, 2024
Advertisement

Inventory System - Pickups:

This was something I already implemented during the halfway check-in, although I needed to rework things a bit because I wanted to have the ability for a single pickup to grant multiple of an item. Each item pickup now has an Amount variable that is used to add the correct number of items.

A snippet of some of the pickup blueprint

Showing Items with Icons:

The inventory UI is arranged like this:

Within the scroll box, we use scripts to insert the proper inventory slots, based on the number of rows we chose and the number of total slots. It can also be toggled with the E key or closed with the X button at the top.

The inventory Slot itself looks like this, and we set the Item Icon and the Text based on the type and number of items, respectively. The icons were found from a Unreal tutorial that I'll link at the end.

You can see that certain items can stack, and others can't, which is determined in the item data using a Struct.

Sorting Items based on Filters:

The biggest task I wanted to take on was a sorting feature. Right now, there are three different filters you can use to sort your inventory: Name, Category, and Amount. They can also be sorted in reverse order by clicking the Sort button again.

I used Bubble Sort for the sorting algorithm, because I was able to find resources online for implementing it in Unreal, which helped a lot. Here's a snippet of the Bubble Sort function:

Sorting by Name was the weirdest part, because Unreal can't natively compare strings alphabetically. I could have implemented a comparison function manually, but I managed to find someone else's string comparison script online, and converted that to work with my own scripts: https://blog.futureofmankind.co.uk/2021/05/23/comparing-strings-in-unreal-blueprint/

Showcase of each sorting type

A tutorial that I used for some functionality and item icons:

0 likes 1 comments

Comments

Aressera

To me this blueprint stuff seems pretty useless compared to writing C++ code directly, assuming you are able to do both. Just look at the ridiculous hoops you have to jump through to do something as simple as sort an array of strings, whereas in C++ it would be a simple matter of std::sort() and defining an appropriate comparator in a few lines of code.

April 01, 2024 06:25 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement