Save Game doesn't seem to be working properly

Hey everyone!

I’m having problems with some certain save game code and was curious if anyone could help! Maybe I’m just making a simple mistake but as far as I see my code looks perfectly fine.

Here’s the problem:
I have a Campaign Upgrade System for my game. When interacting with the upgrade station it open UI to activate the upgrades. I have it so that a variable is saved when interacting with the upgrade station so that when the player unloads and loads back in the game they can’t interact with the same upgrade station. I also set it up to save and load the upgrades so when the player loads back in they have all their old upgrades. Currently the upgrades saving works perfectly, no problems there. But, unfortunately, the saving for the use of the upgrade station seems to not work. My save game code sets the variable to true and then saves it as true, but then when I load back in the world it loads as false. I’ll send some picture in here and if yall have any questions lmk. Thank you for anyone who is able to help or is at least willing to take time to try to help!


1 Like

I see no write ( save game to slot ) in the save code for the upgrade station?


heres a focused image of the save game to slot for the upgrade station variable

1 Like

All of these need to connect, otherwise the save is only executed for station1

yeah i know. i had them all connected, but currently im only testing station 1 so i disconnected all the other nodes to make it more specific for troubleshooting

1 Like

Ok.

I notice you’re getting the save game ref on begin play.

Do you know it’s best to read the save game every time you write to it? Otherwise you can end up doing this

1 Make SG ref
2 Write to SG 1
3 Write to SG 2

But, (3) will overwrite what (2) updated, because the SG not read again first. So the correct order is

1 Make SG ref
1.5 Read SG
2 Write to SG 1
2.5 Read SG
3 Write to SG 2

This avoids the problem. Yes, maybe you don’t always need the reads, but once you have a lot of things reading and writing, it’s the only way to do it.

oh ok. I think I understand what you’re saying. im going to try to mess around with the code and see if I can fix it. ill keep you posted!

1 Like


So I added the save code to the function right before the actual save and it still seems to not be working. same problem as before.

I also tried adding an extra save game to slot before and after the saving of the bioboost and the upgrade station boolean and the bioboost is still saving properly but not the upgrade station variable

1 Like

All I can tell you is, the save game very definitely does work :slight_smile:

The trouble is, you’re trying to debug a bunch of spaghetti :rofl:

Maybe try cutting everything except the bioposts out. See what the problem is, get it working, then re-add the other stuff again.

1 Like

Yeah I know Im not keeping it very organized right now haha, sorry!

I usually keep my code organized but when stuff like this happens it becomes a mess and i dont bother cleaning it up until its done.

Ill try cutting out the bioboosts and lyk what happens!

1 Like

Hey so I just cut out the BioBoost code and had it save the upgrade station variable all on its own. It still doesnt work haha

1 Like

Ok, show me just that bit

1 Like

Sorry, I can’t help if I don’t get the whole picture.

What I’m going to do, is show you a way to use the SG that is very compact, and never goes wrong, gimme 5…

Ive used Save Game code plenty of times before and it works perfectly fine in my game. It seems to be really weird about this one variable and I dont know why. I can hop on OBS and record a video of all my code and send it in a youtube url. would that help?

1 Like

Already done it. Make a function library ( if you don’t have one ), and give it two functions

This is how to code the UpgradeStationBP

That’s it :nerd_face:

For multiple stations, just have an array of bools in the SG. Much easier than trying to do it in the level BP. Each station has an ID ( set in the level ) and the code becomes

So i just tried this. Its still not working. Once again, saving the BioBoost variable but not the Upgrade Station variable.

Also I never did any code in the level BP. The Level BP is forbidden haha. All the code is in the Upgrade Station actor and the Upgrade Station widget

1 Like

The principle is the same, saving and reading a variable.

Check if the variable comes back immediately after loading with a print string.

If it does, the error must be elsewhere…

Hey I seem to have fixed it. Its the most silly goofy fix ever, but it worked.

In desperation, I added a delay of 0.01 seconds to the BeginPlay sequence for the Upgrade Station actor (no changes made to ui code). For some reason now it works. Its persistent and is working across multiple save files, stations and everything.

I am 100% not sure why the delay node fixed it, but it did!

1 Like

Ah, the good old delay.

Good that you fixed it :smiley:

Watch out though, the delay will be different depending on the hardware, so a delay loop is better.

Anyway, much easier way of doing the SG.

1 Like