Casting from an Actor Blueprint to a Widget Blueprint

I honestly can’t understand how to cast this and get what I want (see below).
I’ll try to keep this as basic as possible.
Also worth noting that I’m completely new to this stuff.

I have an “Ammo_Box” blueprint and a ‘PickedUpBoxes’ int variable inside it which is set to 5.

How would I cast the Ammo_Box to my function inside the “FPS_HUD” widget blueprint and get this integer so I can bind it to a text?

For example, the bound text is supposed to say “Amount of picked up boxes: PickedUpBoxes’ value”

I’m not sure what to plug in as the Object Wildcard.

I should also note that there are multiple “Ammo_Box” blueprints in the level. Whenever I overlap a box, the ‘PickedUpBoxes’ value goes down by 1.

I think you’re going about this the wrong way around. Give me 10-15 minutes to put something together for you, then I will try to explain it the best way I can.


Took me a while to put something together but I think this might just work for you. This will require quite some work so be ready to spend some time on this.

First you will need to create a widget blueprint. This will be your HUD, for me it just displays current ammo and plays an animation when ammobox was picked up. Create new variable (integer) and call it QtyPickedUp.

You don’t need all this stuff inside the widget and I will not be showing you how to create animation for this as you can find a tutorial on YouTube. It’s not hard, really. Okay maybe a little but I believe in you.

When widget is created you cast to your character and set a reference to it. You will need it to access the variables from inside your player character (for us it’s ammo)

Third and Fourth images are the bindings for both text fields (x99, ammo(Text Block))

Once you got your Widget setup (you can just have a text for now to see if it’s working) go to your player character (for you could be Third/First Person Character) and create a new integer variable called PlayerAmmo, default (5). Follow the screenshot below. You will need to create a reference variable as it will be used later on to access code inside the widget and set a variable.

Assuming you have your AmmoBox actor ready with a collision component and a mesh inside. You will need a new variable (integer) that will hold a value of Boxes that can be picked up (for me 5). Select newly created variable and tick Instance Editable. This will allow you to set the variable on the actor from the editor without having to open the actor blueprint.

Follow the scripts from screenshots. I’ll do my best to explain and I put some comments around to make it easier.

When your character (for me it’s PlayerCharacter) overlaps collision box for the AmmoBox it triggers a script that sets the variable inside the widget that is used in binding function. Now using a newly created reference to player character you can get and set variables inside your character. You can also play animation from here by using a reference to player character that in turn has a reference to HUD which you can now access and execute a function from inside the widget, and set a variable of how many items were picked.

I will admit this isn’t the best setup but it should work for you. There are a lot of things that could be improved here but I don’t want to make it over complicated, I want you see a working example and maybe come up with something on your own, or modify this to suit your need.

I’m sure you will have some questions and I will do my best to explain.

Remaining screenshots in comment due to limit of 5 screenshots per post.

The animations are quite simple, you just play with position and opacity.

[Gif showing how it works][2]

Thanks! I actually ended up having a very simple solution.

So instead of using the ‘PickedUpBoxes’ integer in the “Ammo_Box” blueprint, I just made a new one in the “ThirdPersonCharacter” blueprint, since I can just use the GetPlayerCharacter wildcard.

Good to hear, happy it’s all working now. :slight_smile: