How can I save the game or specific variables?
So far as I’ve got, which isn’t far, there is a Create SaveGame, and this makes a .sav file with a named slot. It creates the .sav in UE4’s location /Engine/Projects/ProjectName/Saved/SaveGames/ … at least in my case, but mine never quite does what I want:
When you set variables to be stored, it’ll save something like:
CSG_SaveGameClass_C ScoreSAV IntProperty a HudVar ObjectProperty V R /Game/CustomSaveGame/UEDPIE_0_SaveDataMap.SaveDataMap:PersistentLevel.CSG_HUD_C_3 None
ScoreSAV and HudVar were my variables, so I guess it found them. But about updating the current value and loading it etc, I haven’t made more progress.
You need to create a specific SaveGame class at some point, but I’m not sure exactly how to put it to work. I’m patiently prodding the devs to cook up a tutorial, which they say they will.
In your gamestate class or wherever, you have SaveGame to Slot, Does Slot Exist?, and LoadGame from Slot. Or something similar. Beyond that, I can’t figure it out. Would also love to know more.
Each variable, if you expand it’s properties, has a tickbox for Serialise (which is a coder word for Save using JSon). I don’t know whether the blueprint nodes for SaveGame actually make use of that or not.
You will need to create a SaveGame class blueprint specific to your game, and add any variables you need to save into the blueprint. Then, you must add an instance of your SaveGame subclass to the blueprint in which you want to save data.
To save the game, you set any values you need to save in the SaveGame variable, and pass that to the Save Game To Slot node.
To load the game, you call the Load Game From Slot node, cast the return value to your SaveGame type, and get any values you need out of it.
Take a look at the Tappy Chicken sample, it uses this same mechanism to store the player’s highscore.
Cool! Cool!
Thanks. I’ll check it.
The problem here is that the Cast node used in svegame stuff on the flappybird example doesn appear to me. Where can I find it?
The problem here is that the Cast node used in svegame stuff on the flappybird example doesn appear to me. Where can I find it?
The menu for casting objects is context sensitive. If you drag a wire off of the “Tappy Save Game Opject” node, you can then search for the “Cast to [object]” node.
The Tappy Chicken blueprint is very helpful, thanks.
In this screenshot, your “Create Save Game Object” node has an empty “Save Game Class” input, most likely resulting in a failed cast. Otherwise you seem to have a proper implementation of the Tappy Chicken example.
I made a tutorial to clear it, and make it simple process, I hope it helps you.
to make a save file, first i created a subclass blueprint of “saveGame” that i called “Omni_SaveGame” and added a few variables to it. this is where you would add questflag booleans, player stats, inventory items, etc…
then i made a variable in my player controller of type “omni_saveGame” called “Omni_SaveData”. this object keeps all of the important variables during gameplay. so loading a game is just copying a file from disk to set this object, and saving is setting the file on disk from this object.
to load a game, i use a “load game from slot” node, then cast it to my custom saveGame type, then use that to set “OmniSaveData” (the member variable in my player controller that holds the data i use during the game)
this image should explain it better: