First good thing to know is: Is this a multiplayer game?
I would do it the following way:
Each Player, even your SinglePlayer “Player”, has a so called “PlayerState”. You can access the PlayerState
with your PlayerController (So you can get the PlayerController and from it the PlayerState inside of your
UMG Widgets). The PlayerState class is used to save the… Player’s State. So what does this mean?
There are 3 basic variables already implemented. “Ping” (Network relevant), “PlayerName” and “Score”.
Although you can’t set these in Blueprints, you can create your own PlayerState BP Class and just add
your own Score variable.
Now since you can access this PlayerState through the PlayerController, you can just create an Event to
update your own Score variable there. Then you call the Event when you hit the object by getting the
PlayerController and the PlayerState. Normally you give the projectile a reference to your Player. That
way you know who shot. You can get the Controller from a possessed Pawn and from that the PlayerState.
If you have a SinglePlayer game, then you can just use “GetPlayerController0”.
And in your Widget, you do the same, get the Controller, get the PlayerState from it, cast it to your custom PlayerState
and get the Variable to display it (:
(NOTE: The PlayerState Class can’t be set in the “Maps and Nodes” Settings. You need to open your GameMode Blueprint
and check the Class Defaults button at the top bar and add the PlayerState on the right side in the settings)