Variables between blueprints for widget update

I have a blueprint with a variable named enemyHealth. It is a float set default to 100. I’ve created a widget with a progress bar. When I hit the enemy with a cannonball, the variable should decrease with 25 and the widget should update. But…when I try to get the enemyHealth to update the widget I can’t get to the variable. I’m pretty new to blueprints and unreal in general so I probably go about it the wrong way. But I tried it with cast to…but what do I put in the object pin? Whenever I cast to the player I put in “get player pawn”, except this is the enemy and not the pawn. What “object” is required?

widget event graph:

where 25 is deducted from the health, from cannonball BP

The variable in the enemy BP

Create the widget in your enemy, then you have a reference to it, and can update it.

1 Like

Thanks, I made the widget in the enemy en tried to reference it. But I get an error:

Blueprint Runtime Error: “Accessed None trying to read property Ref enemy”. Node: Return Node Graph: GetPercent Function: Get Percent Blueprint: WBP_Enemy_healthbar

The enemy blueprint:

The widget get percent function:

Get the reference from here, THEN add it to the viewport :slight_smile:

At the moment, your reference isn’t set to anything, so you’ll get the ‘none’ error…

1 Like

You forgot to plug in Self into the Create Widget node’s exposed Ref Enemy pin. No data is being passed.

1 Like

I just don’t seem to grasp what needs to be done. As said before I’m pretty new to unreal, so sorry for the dumb questions.

So I have the 2 actor blueprints. Cannonball, where I want to decrement the health float variable. This variable named enemy health is inside of the Enemy blueprint. It needs to decrement by 25 every time the cannonball overlaps the enemy. But when this enemy blueprint variable is updated, it should also update the wbp. The first two I can manage. I can update the variable. But I cannot seem to get the update variable to the WBP. Every time I want reference it I get the error. I just don’t know what to put in the event graph and GetPercent function of the widget blueprint for it to work.

Thanks again for the help, i think i need to watch some more tutorials and try again…i did try to get it to work with blueprint interfaces but the custom event from the interface is not availabe in the widget blueprint. So no luck there either.

Plug in a Self node into the Create Widget’s exposed Ref Enemy pin.

Assuming the above script is in the Enemy Blueprints.

1 Like

I think I made a mistake with the way I set up the collisions and overlap detection. I’m going to rearrange this and try your answers. I’ll keep you posted…

Sure, please do. But you were simply not referencing the actor at all. You’re telling the widget to use This object but you never specified which one.

1 Like

I’ve got it to work. I’ve watched another tutorial which confirmed my lack of understanding (as a beginner) and tried the new method. I didn’t even have to add the widget blueprint because it was already in the enemy blueprint.

The setup is as follows:

widget getPercent:

Enemy blueprint

I’ve followed this tutorial:

Show AI Health Above Head

Thanks for all your help!

1 Like