Adding data only BPs to a struct array with a umg button click

I’m trying to add items to a struct array (Inventory) based on what button was pressed in a umg widget. This is what I have so far but it gives me the “accessed none” error.

This is the UMG Graph
UMG Graph
This is the UMG Designer
UMG Designer
This is my AddToInvFunction
AddToInv Function
And these are what I’m referencing

BP_Metal is a child or BP_Item_Master and BP_Item_Master is a data only BP of the Struct S_ItemData.

As of right now the only thing i have in S_ItemData is a name variable but I plan on adding much more later.

Right now I have it set up so that when you click the top button it adds BP_Metal to the inventory array, just to test functionality. Ideally I want to have the two options in the UMG Widget dynamically generate and depending on what one was selected by the player that item would get added to the inventory. If you can help me with both that would be awesome but I’m sure once I get the functionality down I can figure out how to make it dynamic.

Hey RcarbonelJR!

Where are you creating your reference to BP_Metal in your UI? That seems to be what is creating the accessed none error. I’d recommend making the reference Public and exposing it on spawn, then passing the reference to your UI when you create it. You could save a variable creating the actor reference when you pick the item up (either via line trace or an overlap event).

But it looks like you’re trying to make an inventory system right? If so, you’d want to be adding your inventory references to your character rather than BP_Metal unless you’re trying to change the item’s features.

Have you seen the UMG Inventory Tutorial? It’s really good at teaching you the basics of sending your references to the proper locations. It will need to be tweaked a bit based on your specific needs, but it’s a great place to start.
A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine ForumsUI-_Inventory_Tutorial_Playlist

If you want I can take a look at your project and make some edits that I think would help. Otherwise, I can answer any other questions you have.

Hope this helps!

Entro

I have looked at that tutorial series and many others on YouTube as well. The problem I’m running into is that I’m not adding with a ray trace or an overlap. Its strictly a click based project. I feel like it’s something simple that I’m missing but I’ve been trying on my own for about a week now.

The BP_Metal is the S_ItemData info that would be going into the inventory array in my character. I guess I’m not understanding how to reference it correctly?

To break down what i want to do in a raw form:

  • player clicks to search a location
  • UI pops up with two options that were dynamically created (chosen from an array that has many different findable items)
  • player chooses one
  • Item gets added to player inventory