UMG: Updating score counter each frame

I have a scoreHolder class which holds the current score of my game.

This score is currently being printed to the screen for debugging purposes.

In UMG for my HUD, I’m grabbing a reference to the score and instantiating it in the UMG blueprint as “Current Score”. I set this each frame with Event Tick. I also have the text content binded:

15394-02capture.jpg

However, even though I see the score updating in the print string text, the UMG text block is not updating, and stays at zero. Did I set this up incorrectly?

Many thanks!

Could you try printing both Values in your Widget too? So you can see which value is the one giving you the zero.

:confused: I can’t see the error at the moment. Maybe we can get this working together (:

This seems like you don’t actually get your reference to the score holder.

How exactly do you get that one?

Ah there we go. You need to set that variable first.

Right now you only have a variable of the type scoreHolder_C but not actually the object scoreHolder_C.

You have to get an instance of it and put that inside your variable in order to get this work :wink:

This should only work in the LevelBlueprint I’m afraid.

Well this is interesting, although the Print String node within my scoreHolder blueprint is reporting the scoreVar changes, doing the same thing from the scoreVar’s reference in my UMG graph is producing all zero’s.

Also interesting: In my Output Log, I’m getting a whole lot of
“LogScript:Warning: Accessed None ‘scoreHolder’
uiDesign01_C /Engine/Transient.UnrealEdEngine_0:LocalPlayer_100.uiDesign01_C_6
Function /Game/UI/uiDesign01.uiDesign01_C:ExecuteUbergraph_uiDesign01:004A”

(uiDesign01 is my UMG blueprint)

I’ve created a variable with the type set to the object scoreHolder_C. Then I drag the out pin off to get the “scoreVar” variable.

Yop, your scoreholder is NULL i guess. Check it with the “Is Valid” node.

If you have your scoreholder in the scene you can click on it and after you selected it, you can rightclick inside the graph and click on “get reference” or something. I guess it was done like that.

“I’ve created a variable with the type set to the object scoreHolder_C. Then I drag the out pin off to get the “scoreVar” variable.”

So you never set the scoreholder to this variable. It is empty.

Getting an “Is Not Valid” fire on my scoreHolder reference. I can’t seem to reference it the selection way though, as it doesn’t give me the option in the UMG blueprint.

Ok my fault. Is this the only BP of that ScoreHolder class?

Than you could try getting it with the “Get All Actors Of Class” node and only select the first element of that array. Because you have only one actor of the score holder class, it should be at index 0.

How should I get an instance of it to plug in to the set node? I grabbed a set node for the scoreHolder var, but not sure how to plug in an instance of the actual object.

GameState is normaly the right place for this. But helping him to understand what he needs to do for thos version to work is also helpful. (:

Different question. To make it easier why not handle the score in your gamemode or gamestate class?

You can fairly easily access them and this seems like a gamemode type of thing. Especially if it should be in the HUD :wink:

Well there are a few options.

The easiest would be like eXi suggested to use the “Get all Actors of Class” node and select your Blueprint. You could also pass it down via other blueprints or use an interface in your UMG blueprint which takes your object as input and sets it to your variable.

However I personally would suggest not updating the score in a separate actor blueprint but rather doing it in the GameMode blueprint. It sounds like a very GameMode type of thing to do ;D

And a reference to that is easily obtained. Just use “GetGamemode”.

Indeed.

Though providing both should ultimately be the best thing since it shows what the general problem in the way of thought was as well as an overall better and easier solution :slight_smile:

You are definitely correct though and seeing you all around the Hub you definitely do your very best to do so!

Not at all. I can’t sleep now anyway^^

Alright so you’re almost there. Once you used the “Get Gamemode” node you have the current gamemode. However the system is only acknowledging that you a gamemode instance. Not your gamemode so you can access all basic functions inside the gamemode class but not yours.

To solve this you have to use a “Cast To” node which basically checks which class your current gamemode is. The one you select in a dropdown menu inside of that node or something else (basically a branch for classes).

Just drag out a wire from the “Get Gamemode” node and search for “Cast To”. You should find “Cast To (your gamemode name)” in that list :wink:

Oh I should definitely just move this over to that class then. Is that affecting my problem though?

If you can, yes. You can create just like all other classes. There should be a parent GameState class. I think you need to set it inside the project properties where you also set your gamemode etc. There should be a section at the end after the gamemode for the gamestate class.

This class should handle your overall game. Scores, playerlists etc

Na, only because i’m spaming the HUB doesnt mean i’m all correct.

I just try to help with the easier problems and with questions no one seems to answer. (: You were right with the GameState. I thought about it to but i also thought he would know about it and needs it this way.

If you run into problems i will help you tomorrow. It’s 2:45 am in germany and im tired (: