Hey, so I have an item/inventory handler which holds a dynamic array of all the items the player can pick up. It’s been working perfectly fine so far for getting info from it and spawning and handling items, however, now I need some more functionality from it and retroactively modify it on the run.
Basically my array needs to now also hold how many of them the player has, should be simple right?
Add an int to the struct, and do a ++ on it on the item in question’s index.
However, I can’t for the life of me get it to work, so I appear to be missing something here.
Struct:
USTRUCT(BlueprintType)
struct FDropTableItem
{
GENERATED_BODY()
UClass* ItemClass;
int SellRollValue;
int DropRollValue;
int PlayerOwnCount;
};
When I generate the array of items all of them start out with:
//otherstuff
iItem.PlayerOwnCount = 0; //Player owns 0 of this item at start.
//add struct to array
DropTable.Add(iItem);
Then later when the player picks up an item, I try to do this:
void UWSSpawnItems::AddOwnCount(int index)
{
DropTable[index].PlayerOwnCount++;
}
I’ve logged and confirmed that the index I’m trying to add to are values within the range of the array, I’m not getting any out of bounds issues. I’m simply not able to read and write to DropTable[index].PlayerOwnCount after initializing it?
Edit: Figured it out! I had a case were I didn’t have a proper reference to the itemhandler from the item. While it crashed at trying to read the array, the issue was actually not having the entire instance.