Trouble displaying character stats with widget

Hello,

I’m currently trying to get a widget that shows the stats of a character to show up in a ‘Common Activatable Widget’. The widget is getting added on pre construct.


Then it’s being called when a buttons pressed on the main menu. This is all working fine however the stats don’t update when it’s being added like this.

If I create the widget and add it to viewport inside the pawn with the stats it works as intended. This is how I’m getting the stats to connect to the different UI elements.

Create widget inside widget it’s blank
image

Create widget inside pawn with stats it works
image

Any help or suggestions on this would be much appreciated.

Cheers

Ben

Hello,

I managed to work out a way to get this working by using event dispatchers to track the stats changing. I then bound to the events inside the widget to update the different bars.

This is all working fine with 1 character but once I spawn in more than 1 the bars start jumping around. I’m pretty sure this is because the event dispatchers are sending the stat changes for both characters at the same time to both widgets.

This is how I have it set up

Character has a function that drains his thirst meter. This also has the event dispatcher in it.
image

Then on the pre construct of the widget I get all actors of class with a loop then bind to the event form the character.

This works fine for 1 but breaks with 2 or more

I tried changing the get all actors for class to just a cast to the character but that won’t work.

If anyone could help me with this it would be much appreciated.
:slight_smile:

So I managed to get this to work. I couldn’t use the event dispatchers because it was tracking all instances of the charter stats at the same time.

Whenever a new character is spawned in the world it creates a widget and stores it in an array in the gam mode.

Then in the widget that tracks the stats it get’s a reference to the character and the stats. Using this function the stats are turned into percentages of the different bars.

Then finally inside the widget that displays all the stats it gets the stat array from the game mode and loops through and adds them to the widget.

I hope this helps someone in the future if they run into a similar problem.

:slight_smile: