Serialization/Deserialization of reference to Data Asset for save file?

I have inventory that contains Array of references to DataAssets, saving to sav file and loading works fine. But when i rename/move the data asset, then for players sav files with old references will not be valid. How can i handle invalid references? I have in mind that: when player is loading sav file, if reference path is not able to locate data asset then it iterates through my special Data Table that contains Old to New path/name for fixing/redirecting references. But how and where do i implement that? I have no clue.

And also, for some reason, rarely for my DataAssets that contains references to other DataAssets it resets/null. WhY?

You would need to do this in a custom FArchiver that overrides the some of the operator<<'s provided by FArchive. You’d pull the path out of the data as a string ('cause that what’ll get written out) and then use that string path a the key to your data table.

That’s all in theory, I’ve never gone so far as to make one because it should really never actually come up. That’s because once save games are in the hands of players, changes like that tend to not be happening anymore. You might move files around for new content (like DLC) that hasn’t be shipped yet, but once it does content tends to be locked down.

For save games used by the development team or QA, there is a little more wiggle room for breaking changes. You try to be as accepting as possible, but allow saves to just become invalidated and unusable. Sometimes this is from a direct change to the save game format which you can control with version numbers, but sometimes it’s content like this that is moved or deleted (ie cut features) and the save game just isn’t going to work anymore. Or you’ve added things that now aren’t properly initialized for the rest of the state of the game.

Sure you want to minimize this, but during development you can’t really avoid it.

So long story short: you can try, but it may not actually be worth it. Real players won’t play with every version of the game you make and you can use that to your advantage when developing.

1 Like

Thank you very much, I thought almost like that but doubted and wanted to find a solution. I will be more thoughtful in terms of organizing data assets so as not to move/rename them, But if necessary, I’ll put it off until a major update.

And if it’s not too much trouble, can you answer this question:
I have DA_Craft that contains other DataAssets (DA_Item).


But for some reason (i believe after engine and project update to newer version unreal can happen), they reset:

Did you ever encounter this issue? And what is best to hold the reference: UDataAsset* vs TObjectPtr vs TSoftObjectPtr, because i just used a raw pointer? Or maybe i have to reparent to UPrimaryDataAsset and use AssetManager?

Nope.

That is a complicated question. None of those things should have any effect like what you’re seeing. In theory, you should use TObjectPtr over raw pointers for members but I’ve never seen raw pointers do what you describe.

That shouldn’t have any effect on the behavior of your asset in the Editor.

Also, this should really be a separate post. You’ll get more help with an unresolved post and people responding won’t be scared off by the “are you sure you want to respond to a solved topic” warning.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.