How to keep track of collected coins?

I’m quite new to using blueprints so I’m sorry if this is actually something rather simple but I just can’t think of a way to do this so I’m hoping someone could shed some light on this. I’ve created a blueprint where a coin just bounces up and down while rotating and when my character touches it, it disappears, this works just fine, but I want to also keep count of my already collected coins and show them in my HUD. Right now if I try to print a text it just somehow keeps track of that one instance of my coin blueprint so the Coins Picked variable just goes up to one but not any higher and it also keeps printing the same message all over again. I understand that this probably should be done in a HUD blueprint but right now I’d just like to get the value updating correctly. If someone could maybe show a picture of a blueprint doing this right I’d be really happy.

This blueprint obviously doesn’t work so any help is appreciated.
Thanks!

You need to communicate with the player blueprint or the level blueprint. This looks like the coin variable is local to the coin itself. So if you didn’t destroy it, it would tell you how many times you hit the same coin. What you need to do either in the level or player blueprint is create a custom event that adds 1 to the coin count. Then have this call that event. Take a look at the UE4 videos on the official youtube channel. I believe there is a blueprint video that tells you how to do this.

Thanks you so much!

Hey there! (:

I will give you a detailed answer. Maybe this helps you in the future.

awilliams1701 already said that the counter is local on the coin in your setup. This will only
count how many times the same coin was picked up. Since you destroy him, this will be “1”
and the number will be lost due to the destruction.

What you really want to do is saving the number in a variable that belongs to something that is not
destroyed. This could be the Level Blueprint, but Level_Blueprints don’t like to be accessed through
Casts so easily. So for the beginning, we will take the Character.

Let’s say your Character Blueprint is called “MyCharacter”. Open it up and create a new variable called “CoinCounter” of type Int. Click the icon on the right side (the eye) to make it public (so it can be accessed by other classes).

http://puu.sh/dsiy8/14affa1112.png

Now compile the MyCharacter Blueprint and head over to your Coin Blueprint. Setup the Event Graph like this:

http://puu.sh/dsiHO/ab225a2eb2.png

Get the Player Character (0 if you have a single player game) and cast it to your CharacterBlueprint Class. Mine was “MyCharacter”. Now you can set and get the CoinCounter variable from the return output of the Cast Node. Remember that you need to compile your MyCharacter Blueprint first. Otherwise the new variable won’t appear. Also make sure to make the variable public. This is needed in UE 4.6 and higher.

If you can’t find the correct Cast Node, make sure you clicked “Context sensitve” at the top right corner of the menu that appears if you right click into an empty space of an event graph or if you pull an output into an empty space.

If you still have questions, feel free to ask me. But since it’s 2 am in germany, i will answer your tomorrow (:

Thank you for going even more in depth! This is exactly what I was looking for.