How To Stop A Collected Coin From Respawning On Level Restart

I’m currently working on a platformer/adventure game. I’ve been having issues with designing how coin-collection works throughout the game. As of now, the player goes through the level, and is able to collect about 100 different coins, each a scene object of the CoinBP Blueprint. Problem is, when the player dies/falls off the stage, the level restarts using a console command. Because of this, all of the coins that the player originally collected before the restart, re-appear. I want to make it so that once a player collects a coin, it is permanently collected, no matter how many times the level is restarted. Coin collection is handled in two different blueprints, one in the actual CoinBP, and the other in the player (PhysicsBall) blueprint.

I tried to use a boolean variable with the CoinBP to see if the coin had been collected, and if so, destroy it in the construction script. This, however, didn’t seem to work, since the Coin object itself ends up being destroyed when it collides with the player, reseting the variable back to it’s initial value when the level restarts. Any ideas?

hi an , when you restart the level , your entire level get restarted as it was made in the editor.
i think you can do 2 things.

  1. make an array to store all the collectionable items , link it to the spawn , and save it on hard disk.
    The level start, it load the array , all coin are active, so they remain. i play the game and collect the 1 , 2 , 3.
    Before Restart the game ,i save the array on hard disk , setting off the 1,2,3.
    When the level will restart, it will load all but 1,2,3.
    Check how save your game in the documentation.
    2)You could just respawn the characters, and if you want , the monsters. .

When you restart the level, it is no longer persistent (permanent) and that is why you experience this.

A method of making the coins collected persistent is to send the information to the Game Mode blueprint - which stays persistent during the entire game session - and store it in an array - for instance, you could store the location of the coin. Then, when the level restarts, the Game Mode can ensure that coins at the locations they were picked up will not respawn.

Are you sure? IIRC GameMode will reset as well, at least when I tried OpenLevel node or open MyMap console command

I went ahead and used this solution, and everything seems to be working now! I ended up making a string array in the GameInstance BP, and whenever I would collide with a coin, it would add the coin’s object name to the string array. Then, in the Level BP, I check as the level loads for any names in the string array, and if that object is on the list, destroy it immediately. I have attached the modified Blueprints, in case anyone wants to know how I did it in the future.

Glad I could help! Please feel free to mark the question as answered =)