Download

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.

cf21e8d97c21a85c986bf17807f1651fe149661f.png

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 (https://answers.unrealengine.com/users/64490/gedamial.html)

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

2.png

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.

3.png

The **HUDDELAY **function

db52eb94eb85cd37fd1fdc18f093e5d98744458f.png

The ShowHide function

85d77bd1243539ae737d3911679a6f12a6841df0.png

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.

a6cfdb8aae16a461c7da7e3d25893253c8f9be41.png

----------------------------------- 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