I’m making a MOBA proto type and with my HUD I want to be able to get the health of the character the player is controlling, although I’m not sure how to bind this.
My idea was to get the player controller, use that to get the controlled pawn, and then use that to get the health variables of it, although I cannot get the health variable because it is tied to the character object, not the controller. The only work-around I have in mind is apply all of the characters stats to the player controller and use them from there although this would require a bit janky updating process and blueprint communication. Any other ideas?
Try modifing that. If your character BP is a Child of a master character BP, each character on the board will be running its own instance of that code. Replace the CAST to widget, with your HUD widget. Also, if its not obvious, that master BP also has a Health float VAR. Then, in your HUD widget, youll need a ref to the Master BP (not the child), and then in the progress bar you can set the precent to CharREF.HealthPercent or something similar.
Edit: I should add, that graph should go into the Character Master BP.
Player Health should be in the Player State. Typically you’d create a custom player state class and add character relevant data there. Health, Score, etc.
From here you’d simply get game state → get player array → player state (id of player) → variable.
In what blueprint would I put this? The HUD, the character, the player controller, or something else?
Hey, late response because I’ve been busy. I put everything together as described although I get an error saying accessed none in the character reference variable in the HUD widget. I couldn’t find a fix on my own. The variables type for the reference is the master class object, so I don’t understand why there’s an issue.
In my limited experience, a NONE error is always because your reference is NULL. This is because, in the case of a widget, or a character for instance, there can be many child copies during runtime and it doesnt know which one your trying to target. Casting as I demonstrated changes that reference from a NULL value to the actual target.
Lol … it was a question, as in, what is a Player State? Seems like something I should know as it implies a few usable items, but I dont know about it.