Struct not serializing to savefile

Fixing all my rookie mistakes, there's still issues with serialization/de-serialization of more complex data structures it seems. Attaching debugger to PreSaveGame and PostLoadGame it's clear that they're present on save but not present on load
void AResourceRouletteSubsystem::PreSaveGame_Implementation(int32 SaveVersion, int32 GameVersion)
{
SavedSeed = SessionSeed;
SavedAlreadySpawned = SessionAlreadySpawned;
SavedRandomizedResourceNodes = SessionRandomizedResourceNodes;
}

void AResourceRouletteSubsystem::PostLoadGame_Implementation(int32 SaveVersion, int32 GameVersion)
{
if (SavedSeed != -1)
{
SessionSeed = SavedSeed;
}
if (SavedAlreadySpawned)
{
SessionAlreadySpawned = SavedAlreadySpawned;
}
if (SavedRandomizedResourceNodes.Num() > 0)
{
SessionRandomizedResourceNodes = SavedRandomizedResourceNodes;
}
}
void AResourceRouletteSubsystem::PreSaveGame_Implementation(int32 SaveVersion, int32 GameVersion)
{
SavedSeed = SessionSeed;
SavedAlreadySpawned = SessionAlreadySpawned;
SavedRandomizedResourceNodes = SessionRandomizedResourceNodes;
}

void AResourceRouletteSubsystem::PostLoadGame_Implementation(int32 SaveVersion, int32 GameVersion)
{
if (SavedSeed != -1)
{
SessionSeed = SavedSeed;
}
if (SavedAlreadySpawned)
{
SessionAlreadySpawned = SavedAlreadySpawned;
}
if (SavedRandomizedResourceNodes.Num() > 0)
{
SessionRandomizedResourceNodes = SavedRandomizedResourceNodes;
}
}
UPROPERTY(SaveGame)
int32 SavedSeed;

UPROPERTY(SaveGame)
bool SavedAlreadySpawned = false;;

UPROPERTY(SaveGame)
TArray<FResourceNodeData> SavedRandomizedResourceNodes;
UPROPERTY(SaveGame)
int32 SavedSeed;

UPROPERTY(SaveGame)
bool SavedAlreadySpawned = false;;

UPROPERTY(SaveGame)
TArray<FResourceNodeData> SavedRandomizedResourceNodes;
I've set the specifier for it 🤔 SavedSeed and SavedAlreadySpawned are int32 and bool respectively with similar setups and these work properly
No description
Solution:
In case you haven't solved this yet, the uproperties in the struct must be marked as savegame too
Jump to solution
3 Replies
Beef
BeefOP•6d ago
Struct definition
USTRUCT()
struct FResourceNodeData
{
GENERATED_BODY()

UPROPERTY() FString Classname;
UPROPERTY() FVector Location = FVector::ZeroVector;
UPROPERTY() FRotator Rotation = FRotator::ZeroRotator;
UPROPERTY() FVector Scale = FVector::OneVector;
UPROPERTY() TEnumAsByte<EResourcePurity> Purity;
UPROPERTY() TEnumAsByte<EResourceAmount> Amount;
UPROPERTY() EResourceNodeType ResourceNodeType;
UPROPERTY() FName ResourceClass;
UPROPERTY() EResourceForm ResourceForm;
UPROPERTY() bool bCanPlaceResourceExtractor = false;
UPROPERTY() bool bIsOccupied = false;
// UPROPERTY()
// FResourceNodeVisualData VisualData; // For debugging
};
USTRUCT()
struct FResourceNodeData
{
GENERATED_BODY()

UPROPERTY() FString Classname;
UPROPERTY() FVector Location = FVector::ZeroVector;
UPROPERTY() FRotator Rotation = FRotator::ZeroRotator;
UPROPERTY() FVector Scale = FVector::OneVector;
UPROPERTY() TEnumAsByte<EResourcePurity> Purity;
UPROPERTY() TEnumAsByte<EResourceAmount> Amount;
UPROPERTY() EResourceNodeType ResourceNodeType;
UPROPERTY() FName ResourceClass;
UPROPERTY() EResourceForm ResourceForm;
UPROPERTY() bool bCanPlaceResourceExtractor = false;
UPROPERTY() bool bIsOccupied = false;
// UPROPERTY()
// FResourceNodeVisualData VisualData; // For debugging
};
This is essentially the list of all the resource nodes in the world that I'd like to spawn, with randomization already applied to it. Instead of storing this struct, which is used to spawn the actors/meshes/etc for nodes, I guess I could serialize the actors in some way, although I'm not yet sure how to do that yet - I would assume it's more or less equivalent as actors read from savefile still must be respawned in some fashion. The disadvantage of this way is that I have to re-associate miners/etc with nodes on load as well I believe, since each time it loads they're new entities. I assume there is some way to save some kind of reference between miners/actors for instance. I just don't know if it's worth to try a different way that will likely require a similar data structure when I can't get this to work in the first place.
Solution
Mircea
Mircea•6d ago
In case you haven't solved this yet, the uproperties in the struct must be marked as savegame too
Beef
BeefOP•6d ago
Well that is easy, thank you
Want results from more Discord servers?
Add your server