How can I call my Inventory array struct properly?

Dear Readers of the forum,

In another thread I have spoken about an unknown error that occurs when we try to build a project of merged folders from 2 different projects ( Packaging Results Error: Unknown Error - Platform & Builds - Epic Developer Community Forums ). On this thread, I will be talking about the problems I have with my classes. To explain this issue I have made a list of related aspects.
To start with, I will be talking about the problem I have with making the classes of the programmer project work together with each other. Because of that, information of the inventory array struct can’t be called from another classes, except for the inventory widgdet.

My classes issue list:

1# My Checklist Widget class won’t take information from the InventoryStruct Array that i’ve referenced in the event graph and a function called 'get item count

2# My Item Master doesn’t give any (referenced) information to my ChecklistWidget

The event graph of the checklist widget class

The function graph of the get item count function

the function graph of get item count when executed in debug filter mode

the event graph of the exeptional class when executed in debug mode, the inventory widget class

If someone needs any more information about how I made this project, don’t hesitate to ask. Any feedback at this particular moment is welcome.

1# My Checklist Widget class won’t
take information from the
InventoryStruct Array that i’ve
referenced in the event graph and a
function called 'get item count

Can you provide some insight into how you are adding to/declaring the array ‘Items’? Seems to me that everything is working, but your Items array is just empty.

2# My Item Master doesn’t give any
(referenced) information to my
ChecklistWidget

Can you show how you’ve tried to do this?

The array items is the struct array which supposes to hold the data of my inventory struct. The inventory array is the same array as the array items, they are just named different.

Also, below there’s an insight on my Item Master Class

The refresh Inventory graphs from the inventory widget class

The Item Master class origins from the inventory struct as ‘Class’. And has been called from the input of the function: Get Item Count.

If you need additional information, let me know.

How are the contents of the Inventory array passed on to the Items array?

I can’t see anything that passes information from your GameHUDwidget (where the Inventory array is located) to your CheckList widget (where the Items array is located).

Thanks for the reply. I’ve tried to pass the inventory array in my checklist by targetting the array coming from the gameHUD Widget.

here’s my adjustment:

However now I get a new error. Horray! anyway, the error is an ‘error accessed none’ error. I’ve tried to look up how an none accessed error can occur. But it seems that the cause of this error can vary. I conclude that we need to dig further in my project. If you need additional information, I’m eager to provide it to you.

Here’s the post where I read this: What are Accessed None errors and how do I fix them? - Programming & Scripting - Epic Developer Community Forums

So your problem is with passing the inventory array to the items array.

This can be done in multiple ways. For single player games using only blueprints: I recommend that on the construct event you get a reference to your character or player controller with your widgets.

In your widgets:
Event construct → Get player character at index → Cast to YourCharacterClass → Set CharacterReference.

In your Character class:
After you create your HUDs in the blueprint, set a reference. So make a variable of checklistwidget type and call it ChecklistWidgetReference. Create Checklist Widget → Set ChecklistWidgetReference. Make another variable of inventorywidget type. Create Inventory widget → Set InventorywidgetReference. I believe you have must have done the create widget stuff already as they appear in your game. Just a hint here, name your variables as ThisAndThatReference. This is a way for you to know, that it is a REFERENCE and not the actual thing, it is important to understand the distinction so you get more savvy with your BP programming and it is less confusing when you access these variables in different classes.

Now, since you have these setup, you can access your character from each widget and each widget from your character. Remember though, that if your character dies, it is reset so all your references are also reset. This can be a good thing depending on your game, for example if you want to lose your inventory at each death. You can also do this with the PlayerController, which does not reset when your character dies (or respawns) - so you can keep your inventory. It resets during level change though and if you want your inventory to go through level changes, you need to use saves. But that’s another topic.

Now that you have these setup. You can go to your checklist widget and get your character reference. From your character reference node → inventory widget reference → inventory array. Now you just need to set your items array as the inventory array at a good point in your checklist widget. I’m not sure why are you using tick, but you can add it as the first node in the tick.

Maybe this would work?

P.S. That accessed none error means most likely that you have an empty variable. Can be the GameHUDref or the inventory in it.

Hello again. Thanks for the advice. My array from the inventory probably works I guess. However, my function get item count seems to get no input from the branch I made. That branch needs to check if the class that needs to be declarated is there or not. However, that branch always returns false.

I don’t know why that happens and I need to solve it of course.

If you need any more information, let me know.

Just by looking at things from the pictures you’ve provided, I can’t see any problems. It should print out the numbers correctly if you’ve added your items into your inventory.

One thing I want to state from the get go, is that I’ve had trouble using class as a variable in my structs. I could never find out why it was, but for me the node “equal to class” did not work. I had to convert the class name to a string (if I remember correctly) and use equal to String. I ended up putting an extra string into my inventory struct that was the same as the class name to make it easier.

To troubleshoot your problem, make it print out the class as a String for each object. This way you can see if the classes are correct. If you get no printouts from the classes, print the size of your array to see if it has any items. If the print outs for class are correct, do a printout from the false branch and see if the “equal to” -node is to blame.

Just like you predicted, it prints out the object names when I pick up my items. So, the ‘equal to’ node, it prints out the actor names. If there are two pieces of allumium in my inventory, it prints out the string alluminium twice in a row. So my assumption is that my integer count is to blame. Because the output of my function always returns 0.

Do you have a suggestion on how to fix this issue. should I build my function in a different way?

So the problem seems to be, that your inventory struct doesn’t have the “count” applied to it. If your items are always single items and there are no stacks, you can just leave the Count out of the math and apply +1 to Amount Counter integer with every iteration. If you have stacks of multiple items, you need to check your items, so they have the count in them. Looks like it’s defaulted to zero.

P.S. Also, you need to zero your Amount Counter integer after you have passed it on, otherwise you’ll count on top of the last item.

Thanks mate. It finally works. The next thing I’m gonna do is building a crafting system. but I’ll open up another thread if I’ve any questions for that topic.