Cast to Enemy AI object needed for HUD cast

Hi. I’ve tried searching on here and Google but I’m stuck with this Cast.

What I’m trying to achieve:

Displaying the Enemy’s health above them via an EnemyHUD widget.

What’s Going Wrong:

The cast is failing. I’m not sure what needs to go into the Object input. I have the same set up working for my player character and for them I’m using “Get Player Character”. I’ve tried various other Gets like Get AI etc. Have a bit of a gap in my knowledge about this Object stuff since logically (for me) you should just need the Cast to Node here.
I’m basically trying to get the EnemyHealth Int Var from my EnemyCharacterBP.

The pure "Get X " functions are suboptimal in many way and only really an option for singleplayer. They also only provide values for “must have” things like the player character / pawn, player controller and that kind of stuff.

If you want to use variables directly you need to get a reference to your character. As you said previously you used “Get Character”. This gets you the hard wired object. The dynamic way (and arguably straight up better way) is to provide a reference directly.

This can be done by creating a new variable of the type of the object you want to reference and then in the details of that variable enable “Expose on Spawn”. This will create a new pin when you create this widget and you can just input “Self” there (if you created it from the said character. Important to add here is that if you do this when the character spawns you can’t do it in the construction script because that one is called while the character is still being created to “Self” doesn’t exist yet. You need to use “Event begin Play” in your event graph).

This will set the variable inside of your script to that character as soon as it’s created and also eliminate the need for the cast.

I hope this helps.

Cheers!

I have identical problem, anyone could help?