I will be picking this up on my personal account since I won’t have access to the other one anymore in a couple of days.
When you say stuff like “You can cache the UItem reference using the set node, or just get the item’s texture and apply it to the widget.” (I’m not sure what it means to cache the UItem reference) or “you should add an event or function to the BP_InventoryIcon class that has an UItem parameter.” I don’t really understand how I would get that to work in Blueprint.
Caching just means storing the UItem reference so that you can access it directly later on. In C++, you would create a UPROPERTY() with the type UItem*. In blueprints, you just add a variable in the sidebar with the type Item. Functions and events in blueprints are just like functions in C++. There are some subtle differences, but those should not matter in this scenario. You add a function similarly to variables in the side bar under the functions section. As for events, you right click inside the event graph and type in Add Custom Event, select the option and then name the created node.
Alright so I passed the item through a set node and I got an error that I don’t really understand.
The issue here is that the Set node is not pure, so it needs to be called using the execution flow (white arrows). In this situation, it is not called so it’s as if it didn’t exist. The result is that the item reference would be still invalid and you would still have the original issue. Basically, if you have a node with the white arrows at the top, you need to connect them for the node to work.
I’m more of a visual learner so if you could maybe give me a screenshot example of how that would look it would be a lot easier to understand.
Here is a quickly stitched together representation of what I am trying to say. You add the function/event to the BP_InventoryIcon that takes in the UItem reference. Then in the inventory widget you do what you are already doing but after you add the child widget, you call the function/event created in the previous step on it, passing it the item to display.
Doing that should work. The only other thing that might cause an issue is relying on the On Inventory Updated delegate for the widget to initialize. If this delegate is not invoked after the inventory widget is created, it will appear empty until the inventory changes. Hard to say whether it is desirable, but you might want to call Refresh Inventory after the bind node, sort of like I did in my example.
As for the tutorial, they show assigning the Item into the widget at around 23:00. The only difference is that they are using the Expose On Spawn approach (they set up the widget for that at around 18:20), where they set the UItem reference when creating the widget. This way they cache it before the event Construct is called in the child widget, hence why they don’t need to create a custom function/event. I have no idea whether this is the recommended approach in UMG, as I have said, I have minimal experience when it comes to that. I can also see that they indeed call the Initialize Inventory event after binding the delegate like I mentioned before, so probably do that as well.