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 :
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
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?