And is it safe to retrieve later? Any info welcome, thanks.
Safe-ish. Ultimately you’ll be saving the class path as a string (even though your property is likely a TSoftClassPtr
). I don’t know that raw UClass*
/TObjectPtr<UClass>
will save in a useful way.
You’ll still have to deal with the class no longer existing or, in the case of blueprints, making sure the class is loaded before you use it. For renames, redirectors and core redirects can help make this safer. But deletions or old saves that rely on redirects that are no longer available (either because they’ve been deleted, fixed up or you’re trying to load a save in cooked where redirectors don’t exist) is something to keep in mind.
So it’s safer to use soft class rather than straight raw class? And I should design my save system around that?
I’m only using blueprints btw.
Definitely safer to use soft classes in your save game. I wouldn’t be surprised if direct references didn’t work, though a) I’ve only done saves from C++ and b) I don’t use Epic’s save game object. But something could be different for blueprint, though usually the thing that the savegame uses to write to disk doesn’t work with direct references.
What do you mean by that?
i believe he means you cant save object pointers. A Class is usually ok, if you changed/modify/move things saves are likely to be invalid but that shouldnt happen after ‘release’
I’m confused. So should I store hard class/object references in the save game?
Sorry I probably should have used the term hard reference instead of direct, to contrast with soft.
In blueprint there’s really only the Object/Class Reference or Soft Object/Class Reference variable types, but in C++ there are a few varieties that make things annoying to discuss.
So in your save game you’d want to avoid Object and Class References and only use the Soft versions. It’s possible in blueprint a Class Reference would work, but I don’t think so and it’s worth managing that yourself anyway.
i can confirm Class Reference do work but that doesnt make it a good idea so i agree on your point
Your save files will eventually break, specially if you’re renaming classes and objects. I would avoid serializing any kind of reference as much as possible if you’re able to.