Download

Update HUD

Hey guys,

First things firt: Happy new year! :smiley:

I have two problems:

  1. How to make the number 0 visible. Everytime I create a binding the 0 isnt shown. The integer must always be over or under 0 to be shown… How can I solve this problem?

  2. Why the variable dont update on the UMG? I made an array full of integers. After ending the level it adds a value to the ints and the UMG change the value from 0 to 3, so far so good. But when I end the second level and go back the value should change to 6 but it doesnt. How can I solve this problem?

550a86e7b6b65b003a8de1b0147872ccd1b57514.png

And here is the Blueprint. I use a trigger to end the level. And depending on the time the value 2 or 3 get added. I dublicate the Blueprint and changed the index to 1 so the value of index 0 and 1 should be summed. The thirst time I do the level it only shows nothing (so 0, look problem 1.) because the default value is 0. After ending the level 2 or 3 should be added to index 0 (depending on time). When I go back it shows the number 3 (3+0), so far so good. But after the second level there should be 6 shown because the 3 shoud been added to index 1 and index 1+ index 0= 3+3=6 but the number is still 3…

6678444141171eb6e2c54a74160cc443ed87c826.png

I tested something. I set the default value to 3 for both index (dont know the plural), so it should show 6 when I start the game but it shows nothing (0) after finishing a level and come back to the widget it shows 6 but now it should show 9 because 3+6(3 default value and 3 gets added to the default value)=9… Hm… if you have an idea it would be awesome if you could tell it. The solution for why 0 isnt shown would also be awesome!

Can you post a picture of your array variable setup? How many elements do you have in your array? What is the default value for element 0 and element 1?

I reset the default value from 3 to 0.

5242212c2bae58869339df02c608148c11430c68.png

Guys please, I need help.

Here the full Blueprint of the Trigger:

6f5c868545ec891caf75304122bb6664de85ff74.png

6e6e10fe7e933965a617b2fb4a976a43bd129cc4.png

If its too hard to see something, tell me!

The picture of the the Blueprint in the widget is above but I put it in this post too:

550a86e7b6b65b003a8de1b0147872ccd1b57514.png

IMPORTANT EDIT:
After opening the other level the index reset to the default value but why?

Its like this:
I open a level. I finish the level. 3 gets added to index 0 HUD shows 3. I open the other level index 0 gets reseted to the default value 0. I finish the level. 3 gets added to index 1. The HUD shows 3. But why?

There are a couple of things but here is what I think the reason is:

Get 0 + Get 1, works with an array with two elements.
But you set array
by make array
with one element
which is get 0 + N

so in short, when you try to add index 0 and 1, index 1 does not exist.

Thanks for your answer!

So to be sure:
make array change my array to only one element? For example, I have an array with 2 elements in index 0 and 1 with this code above it deletes the index 1 completely, so only one element of one index is left? I missunderstood the node make array. I thought it overwrites the element of index 0 to 0+3 and ignores element of index 1… But what can I do to solve this problem? I try something now. Thanks for advice!

Edit: Nope, doesnt work. Can you just write down some nodes with which I can solve my problem or if how I try to add the number of the Stars really bad then please tell me a better way to do it! I would appreciate it!

It’s a strange setup, I can’t quite wrap my head around it.

To find a solution you need to understand the problem.
You set the array variable. If you set it with an empty array, it’s going to be empty, if you set it with an array with 50 items, it’s going to have those.
But you set it with a make array node.
The make array node only has one element.
So you set the array variable with an array with one element.
or, you only create one element for the array.

My suggestion, if you wish to keep this setup is to add another element to the make array node. Then it will have the two elements you require. But what that value should be I have no idea, it’s your system.
Another option is to use the “set array element” node. that will overwrite the element at the index, as you seem to have expected the make array to do.

You write, nope doesn’t work, but what did you try?

About a better system to add the stars; well, I don’t know what they are. Are they like “how well you completed the level” thing? And do you need to separate them? If you could just have an int variable on your character that represents the stars, then add X to it depending on the query (which branch check returns true), that seems pretty simple.

Hey,

Everytime a level ist completed Stars should be added. On one widget all Integers should be summed up and on another widget you should see how many stars you got from each level, so yeah I need to seperate them too. If I wouldnt have to separate them I would do it with only one int variable but because I need to seperate them I thought I need an array.

Hm… I dont know what I am doing wrong. Now I use the Set Array Elem. It should overwrite the element of index 0 to 3, and It does but when I open the other level It resets the element of index 0 to the default value which is 0…

I try something now and let you know if I am not making any progress but If you now a better system which can do what I written above please write you ideas. With just an int variable it isnt possible I think.

Yes, when a map is, I guess terminated, the actors are destroyed. Then, when you start a new map, everything is loaded that you put in that map. Actors do not inherently remember their previous state. You need to look into saving and loading data, or read up on the game instance.

Thank you for your help ste1nar!

Last question for today: Do you know why any numner isnt shown on the widget at the beginning? First I need to open a level and then go back via the Pause Menu to the widget without ending the level. Then a number is shown but I dont understand why not direct at the beginning.

I see that you create some widgets in the screen shots. is that the widget that shows the number? If so, it won’t show up until you fire that event.

Which event? I mean I just sum up elements which shoud be existing when I start the game, so it should show up the value of the default value of the index summed up or not? Sorry for all these questions. I know these questions are easily answered from your point of view.

I mean there’s a widget created after the branches, first picture of reply #5. Is that the widget that runs the ‘get text 0’ function?

No, it is a widget which contains a button which creates and add the widget which contains the get text 0 function:

You overlap with the trigger. The game is paused. Widget called “WIN” gets added to the viewport. In “WIN” is a button called “BACK”. Whe you click “BACK” the widget “Worlds” gets added to the viewport. The get text 0 function is in “Worlds”

How all works:
When I start, the MainMenu Widget gets added to the viewport first. After clicking on the button Start in the Mainmenu Widget, the Worlds Wiget gets added to the viewport. Here is a button called World1. After clicking on the button world1 the Levels Widget gets added to the viewport. There are buttons which open different level in the Levels Widget. This is all. At the end of a level there is the trigger he does what I have written above.

So the widget that shows this number, you want it to show when the game starts but it’s not showing up. Is the widget even created from the start? Or could it be that the player character is not created at that point? If so, the cast fails. Try putting a print string after the cast fail pin.

The player character is not created at that point. I tested it with print string. What can I do about it?

You need to either create the character at an earlier point to access the data you want, or store the data elsewhere. Such as the player controller.

I will store the data in the player controller bit it would be nice to know how to create the character at an earlier point. Anyways thank you! I learned a lot of new stuff. It took some doing but it was worth it.
Thank you!