is to make the variable Self_Health a public variable. Dragging out from the as mycharacter pin does not show the health variable. In the video he does not make the health values public.
What am I missing right now that is different from the video?
also
get player character with player index 0 sounds like it might not work in multiplayer with more than one person running around. Is that true?
I am sure you will run into circular dependencies if you go on like this.
Calling Get Player Character or PlayerController is not wise to do inside a widget… why? Because when you create the Widget you already set its owner (the player controller).
So updating your widgets content (like the Ratio of your Pawn) is better controlled over the Owner.
Btw. it is good habit having variables private/protected as default. Better you implement functions called (GetHealth,SetHealth,GetHealthRatio).
I am working on a tutorial series for that: YouTube
Simple workflow would always be:
Pawn took damage -> NotifyOwner(new Health param)
Owner gets the notification and routes the new Health down to the related widgets.
For this you would need to implemented a Function/Event inside your Widget called f.e. UpdateHealthRatio(inHealth).
This function will be called from PlayerController, because he knows the widget which needs to be updated
Awesome, I used your tutorials and everything is working! It feels a lot cleaner to do it this way but I have to admit it does add a few more steps. In the end its worth it.
It is also really useful for me to pass private variables from different blueprints. I wonder if this method is used widely for other things. Should I also pass things like item pickups through the controller? My understanding is that the controller is useful as it can be persistent even after the player changes form or starts a new game.
Well yeah thats the intention. Because your player controller is persistent and a character/pawn is transient, means it may change during gameplay (possess another character f.e.).
For your pickup: The instigator will be the controller because you have an Input called somthing like (PickUp Item). The picked up item will return its item information to the controller. And
the controller will route down this information to the characters inventory array and to the UI Elements which shall show your item.
I think the answer would be everything the PC doesnt have to care about. F.e. if you have a UI interface running, lets say you are in the optionsmenu, where the parent is the Mainmenu. You click “return to menu” you would notify the Mainmenu to hide the options menu again the playercontroller do not care about that he only sees the result on his HUD.
Another example: You jump from a mountain and your pawn break his leg, this will modify the character´s movement speed and no widget in this case (could be too of course), the pc dont care about it and still pressing “W” to move his pawn forward.
I only use the pc as a router, routing information between independent objects like character and widget, both are owned by the pc, but they dont know about each other.
The problem seems to be that in a multiplayer game where I need to do damage and work with client/server setup the dispatchers nolonger dispatch like they should. So right now the only way I am able to make the health and energy bars of each player update on the HUD is by having a tick event on the player controller which is really bad for performance. It seems like dispatchers cant be replicated.