Best way to destroy coin pickup after load?

I have a simple test map with 10 coins, I also have a SaveGame setup which saves the coin count and the coin object name.
What is happening is when I pickup 5 coins and save, then pickup the rest of the five, when I load game, all the coins are back.
What I would like to happen is when I collect the coins, five of them, then save, then collect the rest, and load…is the levels shows 5 coins collected, 5 coins missing from the map, and the other 5 remaining. What’s the best way to set this up,please?


So what you need to do is store this information like coins collected in the game instance, have the save game update the game instance before you load the level. The best way to do this is have an array of bools in the game instance and save game class, and have every coin associated with an index of that array. So give the coins an integer variable just to save its individual index.

In the level bp I set this up:

Then on the coin overlap event you could do something like this:

Just make sure to clear the bool array when you enter a level for the first time. So if you go from the end of level 1 to level 2 you will want the array to be cleared so it can start this process all over again. Also you may need to save an array for each individual level in your save game class depending on how your game works, but this is the fundamental system.

Thankyou for taking time to answer. I appreciate it.

I have the SaveGame system implemented. It’s using MAP rather than ARRAY as I think it’s more efficient.

I see what you’re saying though. Say I have 1000 coins, is there a better way to load them?

Just want to mention that if you have many “coins” ( for example > 10 000) at once as separate BPs and they are moving its better to have one BP that will generate them as instances of InstanceStaticMeshComponent or Hierarchical ISMC.

Well a map does effectively the same thing. Yeah, you would use and hismc. I don’t think you can really ismc for this, I could be wrong.

What do you mean by “load them”? I’m sure there’s a solution.

Do I have to Restart the game every time the player dies, then load?
I uploaded my example project to Git. GitHub - NfrancisJ/UE4_SavingGames: R&D for Saving Games in Unreal 4
Whenever you get some free time, would you mind taking a look please?

I can’t really look at your project, I think epic thinks I’m trying to steal your game. The game keeps crashing saying something about different log in IDs.

You don’t necessarily need restart the game you can just respawn your character, or reload the level. Information stored in your game instance class will remain unchanged.

The easiest way to reset the level entirely is just to reload the level. If you load your map/array of used coins at the beginning of the level then its going remove that many coins. If you don’t want this to happen then you have to create system that determines, whether to load, what to load and why.
(ie. You may want your coins to disappear because you collected them but have your coin count be 0 because you died and lost them. Maybe you want your coin count to carry over from level to level. None of this information needs to be saved/loaded from a save game class until you plan stopping the game all together.)

From what I could see, you are still really early in the development of your game and its mechanics. So you don’t need to worry about the save game class yet, just focus on using the game instance to store information you want to be persistent.(ie. coins, lives, coins removed from the level, etc) when this is working fluidly you can develop a save game system.

The save game class fundamentally is just there to take a snap shot of your game instance and store relevant variables you can access on another day or to revert your game to a certain point after you’ve made a critical mistake like running out of lives. Just focus on using the game instance then the application of saves will make more sense when you have more to work with.

ok…i got everything working except the coin destruction. i made a clean project in 4.19. Hopefully you’re able to open it.
What am i missing? Everything works, but the destroy wont fire.

Ok, it works now and I can see what you are doing. You basically just need to do something like what I suggested earlier accept because you are using a map the part you have left to do is a bit simpler.

I’m trying to get it to work the way you had it. You had this hooked up to the wrong pin, but I still couldn’t get it to work.

But if you just plug it in you the main exec it works on begin play.

I’ll have to do a bit more investigation, I think the order events are called might be the issue.

Ok, so I think I set things up in a way that works. You may not want these events in the level blueprint, but it’s important you find an order of events that works so you’re not trying to set references to save game before the game is loaded.

So I set the level blueprint up like this:

Subsequently disconnected the call from the level restart in the character bp.

Then stopped using the reference to save game object in the bp_coin and used just game instance>save game object instead. The reference to save game object isn’t set at a point where it’s useful.

This works when you press “R”. Pressing “P” doesn’t really do anything as there is no functionality implemented to respawn the coins.

Oh interesting…ok, I will try to replicate what you have.
would you mind zipping and posting the project, please?

Also, while waiting to get home to my computer, let me ask… what are these higher class blueprints for? I’m doing a lot of reading on Level Blueprint, GameMode, GameState, GameInstance…and all the info is a bit vague. You put the UI stuff in Level Blueprint. Is there a reason? In the future, how would I determine where/what is the best place to implement different aspects? Is there a rule of thumb?

The game instance persists over everything, the level blueprint persists for the duration of the level and the classes with in it(pawns, actors, widgets) can only exist after they have a level to exist in. As the the game mode is specific to the level and a bunch of other relevant classes are specific to the game mode. Though they can be changed as needed at run time and can exist with out being used by the game mode.


I don’t know if this is 100% correct but I’m pretty sure this is how it works.

As long as you follow the principle that things have to exist before you reference/configure them this hierarchy should work. You may not want to create widgets in you level bp you might want to do it in you in you character as your pawn and character likely stay the same from level to level. I did it in the level but that isn’t necessarily ideal. I recommend doing things in your game instance and character as these blueprints are easy to access you can cast to them from any other blueprint. I just changed it to create the widget in the character bp because I realized how silly it was to leave it the way it was. GitHub - enearle/Coin_Game

Anyway I hope this helps don’t forget to mark this answer correct if your problem is solved.


I took at look at your Coin_Game, and yup that’s exactly what I want! Thank you very much for taking the time to investigate.