How to keep track of how much collectibles I collected?

Hi everyone!

I want to show at the end of the game how much collectibles the player has collected.
I need to keep that number saved somewhere. So I created a game instance with two variable:
1- Coin Level (To show how much the player has collected coins in the level)
2- Coin Game ( To show AT THE END, how much coins the player has collected in total)

At the end of each level, I set the variable Coin Level to 0. That way, the counter starts to 0 in the next level.

Here’s what I have right now. I function that is called whenever the player collisions with a coin; the function Add Coin, which is inside the player blueprint but is called in the Coin BP :

Thanks for your help!

Looks fine to me

On,ly thing i can pick up is Game Instance (as well as Game Mode) is not just data holder, the code controlling it variables usually should be inside them, so instead of adding in some different class, you should usually should make a function in class that have specific variable and just call it in different class. The main reason behind this practice is to have the adding code in single point and if you want to change behavior on adding coins you would only needed to edit code there, not search that code everywhere where code is added

So i can only see those organization issues, but your code should work regardless

Hey there!
Yes, the code is working right now for the Coin Level (everytime the player collisions with a Coin)

But the part about Coin Game is empty, because I just don’t know how to write it!

But thanks for tip tho! :slight_smile:

This tutorial series may help you. I actually make a collectible coin with a counter displayed to the viewport for the player to see. This number then gets saved when the player collects all the coins in the level, the player moves to a new level and the counting continues. You can probably modify it to fit your needs. Start with video #9

I don’t understand the problem if you’d like to elaborate. Why not just create the Coin Game variable (which doesn’t need to be a float since you’ve only got whole numbers I’m assuming) and add to it whenever the player gets a coin without resetting at the end of the level?

You`re so right! It was in front of me the whole time.
■■■■ it hurts…Thank you very much! hahaha!

Upgrade that to an Answer :slight_smile: