Passing variables from one actor to another and displaying it in UI

Ive been stuck on this problem today.

I am able to target other actors and store them as a variable in my game. I want to display their info as a UI widget.

I am very new to widgets though - so far, I have tried to bind the text block, which creates a function in my UI Widget. In that function I can cast to my player character…but from there, trying to grab the variables hasnt worked.

My enemy baseclass has a Stats component that I made, and in there I keep stuff like Health, Armor, etc.

So how do I grab the variable stored in my target actor and display it in my UI?

Hey @Toothless10101! Welcome to the forums!

Do you think you could post some images of your code? While you may be able to cast to your player character… are you using { GetPlayerPawn → Cast to BP_Character → As BP_Character → Get variable} ? What’s your method? :slight_smile:

the character will have access to the component so you can drag off the pin, or

  1. use get component by class instead
  2. use an interface to do the same
  3. pass the actor and/or component through when you create the widget
  4. bind to an event on either the actor/component to OnUpdateStats() for example

4 is problably the overall best idea so its event driven rather than bind which is basically tick

Crazy weather the past few days, it has prevented me from getting on here.

So I read more and am trying to use a dispatcher.

My plan is to have my “Press R For Radar” logic in BP_MainCharacter that creates a dispatcher, and in that dispatcher have a variable referencing the Current Target. Each child of BP_EnemyBase will listen for that dispatch and check to see if its ID matches with the Target ID . If it does, then it will write its stats to the HUD.

I created a dispatcher in my player base class, called TargetIDForHud. This is set right after my lock on target logic, it should fire every time I trigger it.

In My EnemyBaseClass blueprint, I have it bound to that event in the Event Begin Play node. I cant get it to Print to acknowledge that it got passed to my EnemyBase Class, when I lock on to a target I do not get my print string.

Any idea what Im missing and why I cant get it to ‘listen’?

And in my enemy base class -

binding on begin play could be a bad idea, if the enemy spawns before the player which it will if placed in level then the player will be null on begin play.

to test this just put a delay of a few seconds before the bind but this is for testing only dont keep that logic

1 Like