SaveGame Class Functions

By creating functions inside a SaveGame Class, when I load several SaveGame Slots (Characters), are all those fuctions being duplicated in memory for each instance of the class? Or, is the Class stored in memory, and every instance of that class (SaveGame Object) just stores the data in the variables seperately with a common reference to the memory where the class fuctions are?

I have a SaveGame Class for Saving Characters. I have many functions for processing the data in a saved character, such as building a current profile from a history of data.

Originally I had the functions in a Blueprint Function Library. I started to move functions that strictly use Custom Structs for that particular SaveGame Class (Such as Default Character SaveGame) inside the SaveGame Class.

Some of those functions combine the use of smaller functions that can be independent (no custom structs specific to that particular child class) and are in the Blueprint Function Library, HOWEVER:

A SaveGame Class cannot use any functions from the blueprint library. I had to re-write the functions directly inside the SaveGame Class. This isn’t too big of a deal, but I am wondering this…

Hope this makes sense? I would prefer to keep the functions in the SaveGame Class so that functions are located where the data they use are located. Really, all this does is clean up blueprint code so I dont have to access variables through SaveGame->Variable->VariableofVariable etc. The functions can justdirectly access the needed values for the given object. But this will not be worth it if all the functions are duplicated in memory for each instance of the class.

Functions are from the object class, not the object instance, so if you have 100 instances is still only 1 set of functions. Also functions use up memory except for the memory they need to use while they run and need to store variable data.

Regarding calling external functions inside your SaveGame Class. Don’t think you’re meant to do that. Thing is the SaveGame object class is abstract and kind of weird and only supposed to exist while you use it.

However since you have to call CreateSaveGameObject somewhere to make an instance of the SaveGame class you can call any functions you want there from and on the reference the CreateSaveGameObjecet returns. So you still use FunctionLibrary methods if you want to, but has to be from outside. Personally I usually manipulate the SaveGame object from one of the framework classes like GameInstance, GameMode, or PlayerController.

image

Reason you can’t just add any functions on it is because they requiere a context object, which the SaveGame object can’t provide.

image

Although that’s just a BP limitation. in C++ you can just do whatever the hell you want with it.

Hey thanks! I didn’t think functions would be duplicated, but wanted to make sure.

I was oiginally handling all save game logic in the GameInstance, and a collection of functions in a single blueprint function library.

For my situation, I was thinking it would be best to put any functions that require specific structs found only in the SaveGame, in the SavGame Class itself. I was hoping that this way, if someone wants to create a mod for a different savegame class with different structs available to it, they could replace all the functions needed easily in the custom SaveGame Class.

Just as well, I access the SaveGame Object often to get information on a character to display, so makes it easy t pull of the savegame variable and perform a function to get a collection of desired data to display without having to connect variable inputs to the function…just call te function on the object and get the data i need in the format needed to display.