Getting a variable from a BP to a Widget

Allow me to prefix this with an apology, I know, I can hear the collective sigh at this question.

At saying that i have google the living hell out of this question and can’t find the answer, I’ve been stuck on it for over a week and can’t figure it out, I asked on the AnswerHub but got no answers. I’m probably missing some incredibly basic functionality here, so again, sorry.

That said:
I’m simply trying to get a variable (Integer) from BP_Inventory (which i made as an actor type) into a widget (WID_Inventory). I’ve found a number of guides showing me how to do it but they all use the player controller as the reference object for the “Cast to” node. I don’t want to include the Inventory inside the BP_MyPlayerCharacter apart from anything else, because there is enough going in there already.

What i’m TRYING to do, get the max bag slots from BP_Inventory, then in the widget, multiply that by 75 and change a size boxes Height override based on that number.

If possible i would rather use V2 as this doesn’t require the “Get All Actors Of Class” node, which I’m told is resource hungry.

Just to clarify here and answer what questions i can before they’re asked. If I’m teaching you to suck eggs with this, i apologize, I’m not sure what is obvious to an external viewer and what isn’t.
The WID_Inventory is then placed/referenced inside another widget called WID_Interface. which is what is being created and printed to screen in the BP_MyPlayerCharacter
V1 and V2 are the two methods i have attempted. One at a time, not both at once :slight_smile:
In V2 I created a variable of type BP_Inventory reference.
The numbers i have written in red next to the get BagSlotX variables and the SetBagSlotMax variable are the defaults. So they should be returning a value of 200 as the custom event “MaxBagSlots” isn’t being called yet.

Using V1 i get my cast failed text back
Using V2 i get the error “PIE:Error: Error Blueprint Runtime Error: Accessed None trying to read property BP_InventoryRef from function: ‘ExecuteUbergraph_WID_Inventory’ from node: Set Height Override in graph: EventGraph”

Thanks in advance for any help.

So I think I understand what’s going on, and here’s my suggestion:
inside the widget WID_interface, create a variable of type BP Inventory. Check the editable and expose on spawn checkboxes. Now in the character, when you create the widget you can now directly set that reference with your inventory BP, which I assume you have a reference to inside the character.
Then, in the construct event, get all of the WID_inventory widgets and set their BP inventory ref variable with the WID_interface reference.
Does that make sense?

sssssortof, I’ll give it a shot and let you know :slight_smile: Thanks either way ste1nar.

As i suspected this was an easy fix so just to update for anyone else struggling with this same problem: i got it working like this.

b763260d8fbf44055fb349026e039c9c0efe6914.jpeg