Coin Counter HUD not working

So basically when the player picks up coins, I want it to update to the HUD I created.
I added a print string and that works when I overlap the object but it’s not updating to the HUD.
I’m still new to UE4 so I’m sorry if the solution is so simple.

35790-coin_hud.png

Hi, you need to store the coins count variable somewhere else, cause the coin gets destroyed after you collect it and you loose the coin count, GameMode would be a good choise, so you create this coins count variable there and when coin gets picked up you’d cast to GameMode and update the countVariable.

So here’s what you need to do:

1- Create a MyGameModeBP (blueprint) if you haven’t yet , (choose MyGameMode class as parent).

2- In MyGameModeBP create a variable integer CoinsCount.

3- In your CoinPickupBP add these nodes and it should do the job:

I would then also suggest this video to give you a good understanding how the UE4 is setup.


Good Luck :wink: !

Ok, firstly, welcome to your journey with Unreal Engine 4.

What you need is to store the coin count variable in a main blueprint such as your PlayerController or the Main Level Blueprint, Game State, Player State, or Game Save depending on weither or not your values of the variable are to be replicated.

The first part of your visual script code using Blueprints shows you are printing the text for 1 coin each time with an addition of only 1 count and you’re destroying the object before continuing the rest.

The problem with count would be if you destroy the object and only are updating the variable in the object you are destroying the variable will always have the same value it starts out with when create, which in this case is 0 which is why it is displaying a value of 1 twice.

To keep the coin count consistent, you need to reference the variable from outside the class/blueprint/object you are destroying.

You’d do this by storing the coin count in for instance the main level blueprint, and getting a reference to that variable in the blueprint and casting to access that variable and set or retrieve the variable data/value.

You’d cast to the HUD text object and set the value before the coin is destroyed.

You can also for simplicity use an Event Dispatcher or Interface.

Hi,

i recommand you to store your coin not in game mode but in a more appropriate location such as in your player states.
You can simply download the Multiplayer Shooting template to understand the concept.

Hey, that would be good if his game was multiplayer, in a multiplayer game “GameState” is used instead of GameMode, cause only one GameMode exists on the server and clients don’t have direct access. So yeah then each character would keep count of how many coins have collected.
However, if he only has one character it doesn’t really matter where he stores it, he could just create a new blueprint for that. There are always many ways of doing something in UE4. The reason I suggested GameMode is cause as I said only one GameMode exists in a game and is meant to handle the gameplay stuff and easily communicate between other classes. It is also nicely explained in the video I posted…

Jurif explained the concept below with an example node setup similar to what I was mentioning when you use cast to access the external variable stored elsewhere.

He also explained the multiplayer server/client concept vs. the single player version when dealing with certain Blueprints and using certain methods.

You can check out the Event Dispatch version showing coin collection in the Content Examples Level_Scripting map.

In your case starting out you’d just store your coin count variable in the main Level Script Blueprint as is shown in the 3rd attached picture.

To decide on where to store variables you can lookup some of these topics.

Game State: (Multiplayer or Non-Multiplayer)
https://docs.unrealengine.com/latest/INT/Gameplay/Framework/GameState/index.html

“Game Mode: (Non-Multiplayer Considered)”

Player Controller: (Multiplayer or Non-Multiplayer Considered, Depending on Replication, a Pawn would lose score but the controller would not.)

Player State: (Multiplayer or Non-Multiplayer Considered)

Or pretty much anywhere else.

As is discussed in the documentation:

Quoted: “The GameMode is set for each level, and GameModes can be reused in multiple levels.”

And this can help tell the difference:

The next thing, once you figure how to handle the storage would be how to display the data which can be a number of ways, personally, I’m using UMG for that now.

You can check out Tappy Chicken which features another method and uses GameSave.

GameSave for saving and loading score data:
https://docs.unrealengine.com/latest/INT/Gameplay/SaveGame/index.html

GameSave:
https://docs.unrealengine.com/latest/INT/Gameplay/SaveGame/Blueprints/index.html

Thanks so much for replying so quick :slight_smile:
That all works but I’m still unsure how to set it to the HUD?
Could you possibly screenshot it?

I have a coin UMG sorted and the coin pickup works I just can’t get it to display :frowning:

The print string is working and it’s adding up the coins but it’s not updating to my HUD :frowning:
I think it’s maybe the blueprint of my HUD

Hey, well first if you haven’t yet create a new HUD blueprint and choose “HUD” class as parent.
Then open the new HUD_BP you just created and add these nodes :

Then you need to set your new HUD_BP in the WorldSettings like this(look at right side):

This will work and I also recommend you to check out the Content Examples -HUD , it is a good example, but already you can see HUD can be pretty simple to do, in same way you could draw textures in positions and add hitboxes to detect clicks and so on. I need to go sleep now, but I’ll check back tomorrow after work, good luck :wink:

Someone managed to make the coin counter using the rolling ball example of unreal???
I can not do mine, someone can post all used blueprints???