Saving Asset Ptrs

For the game I’m working on we’re going to be having a lot data representing assets being passed around, to minimise the potential overheads of having references to materials and textures etc, I am storing data to objects as TAssetPtrs.

The issue comes when trying to save this data, I’ve set up a simple example, and I can save and load the data fine, but Unreal doesn’t like serialising AssetPtrs out of the box, and advises that I use FArchiveUObject to store the data. I’ve looked around quite a lot for reference on this, but outside of Ramas saving and loading tutorial (which I don’t think QUITE applies to this scenario) I’m struggling to work out how to use them. My basic understanding is that << is both reading or writing data into the archive based on whether ArIsLoading or ArIsSaving is true, so I’m simply making use of that (clearly in some way I’m either slightly or hugely mistaken in my implementation)

Like I said saving and loading for everything else is working fine, so I think other aspects of my process are okay, it’s just particularly how to save AssetPtrs. My understanding of the archive system isn’t great, so I imagine it’s something I’m doing at the actual point of trying to read the information into/out of the archive.

Here’s the struct data for my saves:

USTRUCT()
struct FSavableDataFile
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY()
		FText textContent;

	FArchiveUObject texture;

	FSavableDataFile(){}

	FSavableDataFile(FDataFile fileToCopy)
	{
		textContent = fileToCopy.textContent;
		texture.ArIsSaveGame = true;
		texture.ArIsSaving = true;
		texture << fileToCopy.texture;
	}

	void LoadFile(FDataFile& fileToLoad)
	{
		texture.ArIsSaveGame = true;
		texture.ArIsLoading = true;
		fileToLoad.textContent = textContent;
		texture << fileToLoad.texture;
	}
};

In case it’s useful I’ll include the related save classes below.

The actual saved struct:

USTRUCT()
struct FNoteSaveData
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(SaveGame)
	    UClass* noteType;
	UPROPERTY(SaveGame)
		FVector location;
	UPROPERTY(SaveGame)
		FRotator rotation;
	UPROPERTY(SaveGame)
		FSavableDataFile data;

	FNoteSaveData(){}

	FNoteSaveData(UClass* classType, FVector newLoc, FRotator newRot, FDataFile fileData)
	{
		noteType = classType;
		location = newLoc;
		rotation = newRot;
		data = FSavableDataFile(fileData);
	}
};

and the actual save and load functions:

void ANoteTestGameMode::SaveGame()
{
	FString PlayerName = TEXT("PlayerOne");
	UNoteTest_SaveGame* SaveGameInstance = Cast<UNoteTest_SaveGame(
        UGameplayStatics::CreateSaveGameObject(UNoteTest_SaveGame::StaticClass()));
	SaveGameInstance->PlayerName = PlayerName;

	TArray<AActor*> foundNotes;
	UGameplayStatics::GetAllActorsOfClass(GetWorld(), ANote_Base::StaticClass(),
        foundNotes);

	for (int i = 0; i < foundNotes.Num(); ++i)
	{
		SaveGameInstance->savedNotes.Add(Cast<ANote_Base>(foundNotes[i])->GetSaveData());

		FDataFile tempData;
		SaveGameInstance->savedNotes.Last().data.LoadFile(tempData);
	}

	UGameplayStatics::SaveGameToSlot(SaveGameInstance, SaveGameInstance->SaveSlotName, 
        SaveGameInstance->UserIndex);
}

void ANoteTestGameMode::LoadGame()
{
	UNoteTest_SaveGame* LoadGameInstance = Cast<UNoteTest_SaveGame>(
        UGameplayStatics::CreateSaveGameObject(UNoteTest_SaveGame::StaticClass()));
	LoadGameInstance = Cast<UNoteTest_SaveGame(
        UGameplayStatics::LoadGameFromSlot(LoadGameInstance->SaveSlotName, 
            LoadGameInstance->UserIndex));

	FString PlayerNameToDisplay = LoadGameInstance->PlayerName;
	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, PlayerNameToDisplay);
	}

	FNoteSaveData tempData;
	ANote_Base* tempNote;
	FDataFile tempFile;
	for (int i = 0; i < LoadGameInstance->savedNotes.Num(); ++i)
	{
		tempData = LoadGameInstance->savedNotes[i];
		tempNote = GetWorld()->SpawnActor<ANote_Base>(tempData.noteType, 
                tempData.location, tempData.rotation);

		if (tempNote)
		{
			tempData.data.LoadFile(tempFile);
			tempNote->SetData(tempFile);
		}
	}
}

Thanks ahead of time for any information anyone can provide!