Hello everyone. I started using UE5.4.1 last Friday after deciding on a whim to make my own game and see how much I can expand it over time. I have no coding experience at all so forgive me if this is a really stupid question but can someone please tell me what I’m doing wrong here?
I’m using an array of structs for my inventory and I’ve managed to figure out how to limit it to four slots. I’ve created an actor which randomly picks out one of four items from a pre-defined array each time my character initiates a collision and I’ve been able to add the name, texture 2d icon, asset name, and the default quantity of 1 to my inventory array each time I interact. The icons are then passed on to my widget to display.
But now after working out how to stop items being added to my array once my four inventory slots are full I’m trying to make my blueprints check if the item is already in the array and if it is to then add 1 to the quantity in the inventory, and if it hasn’t to add the item to the next index slot. Nothing I try is working and my inventory still keeps getting filled with 1 of whatever four items are randomly generated first. Here is my code from start to finish in case anyone is kind enough to tell me where I’m going wrong.
- The blueprint which produces one of the four random items each time I interact with the actor:
- After getting the item this works out whether all four inventory slots are full and, if they are, stops me adding more and prints to the screen that the slots are full:
- This is passed to a function that determines whether the item is already in the inventory and decides which function gets called next to add it to the inventory. This is where I feel I’m going wrong somehow. No matter which variable I attach to the FIND node for the array the result when I’ve chcked has always been -1 even though I F8 and can see the item being picked up is already in there. Is my boolean wrong? Am I using FIND wrong? Do I need to be setting my inventory reference somewhere else?
- After it determines the item isn’t already in the inventory it adds it and updates the widget. This bit definitely works as intended, or works too well it seems!
- The function for adding 1 to the item quantity in my array if the item was already present before being picked randomly in step 1. I have no idea if this works since it’s never been called.
Any help on what sort of noob embarassing mistake I’m making would be hugely appreciated, thank you in advance!