Actor component & UMG Casting

I made a player health system in my character BP With various Variables and functions, And also a UMG widget that was casting to the player character BP to get those variables so it could update the health bar values and such. Everything worked perfectly :slight_smile:

But I am changing to using Player controllers for my characters now, and thought I would like to make my health system a more modular stand alone component that I could just add to any actor and also reuse it in other projects down the line.
So I Migrated all those functions and variables to an actor component, But Im having a hard time casting from the UMG widget to the actor everything I try to set as the target on the Actor component cast node is giving me errors. and Im not sure what the issue is.
try to get owner / actor / parent everything fails so the status bars are not updating :(.
I have also tried sending those varibles directly to the UMG widget from inside the actor component.

Also quick question regarding best practices and performance, Is it better to cast from the UMG to and actor to get the variable values or better to cast the varibles from the actor to the UMG.
Or does this not have any pros or cons and its just the same.

I made everything in the BP because it is easy, i create a variable to UMG in character BP at start and update UMG variable it when i need it.
I have also tryied making everything in the controller, using the same idea, create a reference to your UMG at start, and then just get it and update UMG variable

I have also done this.
I created separate Variables inside the UMG and then created the UMG REF inside the actor component and then pulled those variables from it. Then I set from them with the ones inside the actor component.

As far as I know organizing where data is held and how it is transferred in singleplayer games it doesnโ€™t matter too much as long as the scripts that are trying to talk to eachother are both spawned. For multiplayer things need to be organized a bit a better.

Generally for my personal use. I create all the widgets that will spawn from player controller in the begin play and create reference to each. Create a function on the player controller, that will pass the health variable to the widget. House the health variable on the player character with damage for taking a hit. At the end of the Event Take Damage function, I will call the reference to the player controller and the function that updates the UMG through the player controller.

This setup allows the player controller to transfer all data around while housing very little. I am not sure if this is best practice, but I find it works best for minimizing errors.

As for doing this with a player controller, a player character, an actor component, and a widget. I think it should be setup like this:

Player controller: Holds reference to widget, player character, and actor component.
Add update function: Takes current health variable from actor component and passes it to UMG.

Player character: Attach actor component and set the player health variable from the actor component. At the end of the event take damage, call update health component function.

ActorComponent: Setup Health Variable( any other variables you want to create as well)
Setup Update Functions that pass information from the actor component to the player controller.

So the idea is Player Controller will be the switch board. Player character is where the change to the data starts. Actor Component will have all the functionality for changing the data(damage/healing math), and will receive updates from the player character and pass it to the player controller to display onto the widget. This makes it a bit more modular. Hope this helped answer the question.

Big thanks for your Insight and detailed breakdown :slight_smile: