How to cycle through items from inventory

Hi everyone.

I’ve started a basic inventory system with 3 slots following this great tutorial.

And I was hoping to tweak the code a bit to only have one button that displays the currently selected item and lets me cycle through picked-up items.

Something like this (but with item cycling functionality):

Here’s what I currently have in the FirstPersonCharacter:

In my widget (for highlighting the selected item within my current 3 buttons):

What would be the best way to proceed? From my research, it seems like I need to increment the selected index, but I’m not sure under which conditions I should do that, or how to properly update the widget to support a functioning “one-button” cycling logic.

I assume I would also need some sort of logic to set the max number of items I can carry in my quick use button?

Thanks a lot!

hmm, that switch on int seems to be a bad way of doing it.

i would have a list of items and interact that way.

also i’d have a scroller widget, where you can get the item by it’s index then cast.

to answer your question, you’d increment the index whenever you want to select the next item. for example on a button press.

you also need to account for overflow, and restart at 0. in both directions. (eg when going <0 too)

in case you’re interested i’ve made a foss plugin for inventory that works in a similar way.

you can get some inspiration from it if you want. jerobarraco/Inventory: A simple and easy inventory and flag system for Unreal - Codeberg.org

i think it has a demo ui too, but maybe it doesn’t.

Thanks as lot for that!
Where should I drop the files to install your plugin properly?

Could you also elaborate on where/how I should set up my list of items?
If you have any example of blueprint flow that would be super useful.

All good, glad to help :slight_smile:

in your plugins directory, just download and copy them. like so

then enable them in the .uproject file

sure, but can you explain your question a bit more i don’t quite understand what you mean?

the way i’ve organized my things are:

struct for items > data table of items > subsystem that handles inventory

inventory manager actor > inventory ui

the inventory subsystem (inventory) loads the data table, and keeps a list of items loaded. alongside other runtime (transient) properties, like locked, quantity, cooldown.

the inventory manager communicates with the inventory subsytem through delegates, and updates the ui accordingly.

the ui only manages the ui code, like creating new widgets for each item. removing widgets on consumption. animating things.

it’s a bit of an MVC pattern (which is usually practical for ui stuff)

the subsystem is like the model, as it keeps track of the actual information.

In your game you usually interact with the subsystem. telling it to modify an item, to use it, consume it, or ask whether it’s available or not, specifying the data table, etc.

the manager is sort of the controller, though the subsystem also has some logic.

and the ui is … the view, of course.

my plugin has stub code for the ui for the generic stuff (binding, creating the ui, show and hide)