Trying to understand how to display "You killed PlayerName" with Widgets/C++

Hello guys.

This problem’s been persecuting me for a while.

In C++, I can know where the player kills another one.

Shooter is a FirstPersonCharacter and the code is from a Weapon class.

Now, I set the Shooter’s LastPlayerKilled variable to the Character that was killed.

I’d like to print on the screen (HUD, UMGs, whatever) the string You killed PlayerName

Obviously, the string should disappear after a couple of seconds and re-appear anytime the player kills someone.

I’ve experienced many issues doing that, as you can see here, in the last 3 questions (

Any tip? I need help.
I already tried to take a look at ShooterGame’s code, but it’s full of useless stuff.

I’d probably use UMG, I think HUD is the old way of doing things at this point. What I’d do is spawn a UMG widget with the relevant text based on your state/event and then set up some logic in the widget to remove itself after a specified amount of time. You can store and set a text variable on your UMG widget so it would be possible to set up a general class of widget that could handle any message you want using this method.

How do I achieve this? That’s the main problem, I don’t understand how to set a delay to a UMG

Here’s what I’ve done for now:

I created a FragEarned Widget Blueprint

Which has a ChangeText function to which I should pass the name of the player dead in order to change the string of the message to appear.

The **HUDDELAY **function

The ShowHide function

What I need to do now is to call the ChangeText function from a C++ class.

I know there are alternatives, but I already tried those.

For example, I tried binding an event from the GameMode. But since my game is going to be a Multiplayer game, I read that the GameMode isn’t good for this kind of HUD.

----------------------------------- SO? -------------------------------------

So is there anyone who’s willing to help me in this damned issue?

Re-Reading your previous thread your main issue now is that the message gets printed only once, right?

I’m seeing a logical issue in your Show/Hide call sequence. Where exactly are you setting the Visibility back to “Visible” after hiding it the first time? Merely setting “To Display” boolean to true is not enough as your logic ShowHide needs to be called at least one more time - i.e. exactly after the “Set Player Killed Message” node sets the player message and exactly before the HUD Delay sequence goes through. If you don’t do that, how will the text message be visible the second time? The first time probably works because the text message is already Visible (by default) but set to a blank string.

I can’t think if anything else I’m afraid - overall your event dispatcher approach looks alright to me apart from this logic issue.

This is how I do my kill feed:

The main “Master Widget” has a TSubclassof<> variable which specifies a type of UserWidget (in my case, a UBZGame_DeathNotification). I create a widget based on UBZGame_DeathNotification in the content browser and then set the Variable in the master widget to that new widget. The master widget also has a UPanelSlot variable declared in C++, and I set that variable in the event graph using Event Construct - to one of the items in the designer.

When the player is notified of a death, it creates a new death widget as part of the master widget, sets two FText variables on it for the player names, and adds it to the master widget in the slot that I specified.

Over time the widget fades itself out to completely transparent then removes itself, and is marked for destroy.

Blasphemy. ShooterGame is a fantastic resource and if it does something a particular way, you should probably follow it. There’s a reason things are done the way they are.

Mhm… alright. So where should I put the SET to visible = true node?

Ok I resolved taking a leaf out of a project I did months ago. I completely forgot to set the Widget visible at first.

Yes, Blueprints have this effect on me