Or even Display in the actual level I dont mind.
Each level has coins to collect right.
At the main menu how would I display how many coins you have over the total? (FOR THAT LEVEL)
Many thanks to anyone who has time!
Cheers
Uh…I’m not sure how detailed an answer you need here, but I’ll try to just touch on everything [DISCLAIMER: This is not necessarily the “best” way to do this, but it is a way to do this]:
-Put some sort of int coin variable in your character blueprint somewhere. (You can also use the player controller or other places if you want, just as long as it is somewhere accessible.)
-Make the coins so that every time you overlap one, it adds +1 to your int coin variable. (This can be done a lot of ways, but casting to the character blueprint and just adding 1 is probably the most normal one). Also, destroy the coin actor on overlap as well, assuming you are making a “normal” coin system.
-Make a UMG widget in your content browser, and put a text block (or was it the text box? Use the one that is entered by you rather than the player. That one.) wherever you want it on the canvas panel.
-Create the widget and add it to the viewport somewhere on Begin Play. Assuming this is a single player game, you can use your character blueprint, your game mode, your player controller, wherever you want. Just make sure it is created and added to viewport, 2 nodes.
Okay, now that you have done all of that, you get to pick between the easy way or the less heavy way:
Easy way: Click the Bind button in the details panel for the text of the text block. Inside the bind, just cast to the player character, get the int coin variable and plug it into the output node. It should automatically convert the int to text for you. Keep in mind, that it will be spamming and doing this conversion every frame. You probably won’t notice if you don’t have a lot of things in your game, but you can’t do this for everything if you are making a more complex game.
The way less heavy way:
-You can use casting to take the information from the player character (or maybe the coin on pick-up) into the UMG widget and use a custom event to set the text block (set text node). Make sure the text block is a variable. You will also need to make sure to call this custom event whenever you pick up a coin (the UMG widget will have to be made into a variable off of your previous create widget node).
EDIT: Oh, you wanted it “over the total”? So, something like 10/100? Use more than one text block then. Only the first one should change and the other one can just say “/100” right next to it then.
I have another idea as well now:
For the way with the binds, instead of putting the cast inside the bind function, you can just do one cast on Event Construct and turn it into a variable. That is a lot better than casting every time.
Thanks for reply mate especially that long.
I have done all this, the next step im actually after is displaying how many of the coins you have gathered in a specific level over the total in that level.
Oh, I see. Like you have a different total number of coins each level?
You could try making an int variable called “Coin Total” in the player controller (it has to be the player controller because the player character will die and respawn a lot).
Then, on begin play for the player controller, you could get all actors of class for your coins, then drag out the result and set your Coin Total variable to the length.
Then, all you would have to do in the UMG widget is cast to the player controller on construct and set that second text block to the Coin Total from the player controller.
Yeah I don’t know why but I was over complicating it. I just created variable in game mode with binding to widget text. Then In level blueprint cast to all actors get length and set the variable in the game mode done. Just make it vanish after 3 seconds.
Thanks!