How do I add an item to my inventory with a UMG button click?

I’m making a click based project and I’m trying to add an item to an array with a UMG button click. I have watched many tutorials but the only ones I can find involve ray trace or overlap events. Because I don’t have a physical player in my project I haven’t figured out how to work around this. Here’s what I have so far.

Below is my content browser. S_ItemData is a struct with all the variables of what the item is. Right now it only has a Name value. I plan on adding much more variables once I have figured out how to get this to work. BP_Item_Master is a Data Only BP that has the S_ItemData Variable. BP_Metal is a child of BP_Item_Master with the S_ItemData info (Right now just the name) filled out.

Next we have the widget BP for my test. Basically it has two buttons thats gives the player two options, right now I have only done anything with the first option and have set it to always be metal. I do not get a failed to cast print string here but I am also unsure that it’s actually setting the ‘item selected’ to BP_Metal correctly.

And lastly is the ‘AddToInv’ function I have in my player controller(where my inventory struct is held). This is where I am getting the failed to cast printed to the screen.

I am completely lost on this and have been trying to work on it for about a week now with no luck. Any help or suggestions is much appreciated. Thanks.

There is only to reason to fail in a cast, first one: your variable is null, In your images I saw that you set your variable item selected before call your function “Add to Inv”, but how did you set the value for your metal variable?, if is null then null so you cannot cast, there is a node to check whenever a variable is null called “IsValid”, and the second one is: if you set properly your metal variable, the only reason to fail has to be because that specific object is not an BP_ItemMaster child

Check all this!

Cheers!

The Metal variable is a direct reference to the BP_Metal, while ItemSelected is just an actor ref. So i’m setting the metal reference wrong because I know that BP_metal is a child of BP_Item_Master, I have tried deleting and remaking it a couple times. I will try running it though a IsValid node in the mean time.

Lets assume for now that it isn’t valid. How would I go about setting up the reference to BP_Metal?

Edit: So I ran the Metal variable through an is valid node and its returning null. Do I need to use a ‘Get all actors of class’ node? If so, how do i set that up? If not what do I need to do different?