Here’s my code. Not what’s wrong. Or why I’m having such a hard time with structs in general. Like why I can’t just make a c++ struct from the editor. Or having to do something weird.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/SaveGame.h"
#include "Structs/SaveData.h"
#include "Serialization/ObjectAndNameAsStringProxyArchive.h"
#include "MeatSaveGame.generated.h"
/**
*
*/
USTRUCT(BlueprintType)
struct FMeatSaveGameArchive : public FObjectAndNameAsStringProxyArchive
{
GENERATED_BODY()
FMeatSaveGameArchive(FArchive& InInnerArchive)
: FObjectAndNameAsStringProxyArchive(InInnerArchive, true)
{
ArIsSaveGame = true;
ArNoDelta = true;
}
};
/**
*
*/
UCLASS(BlueprintType)
class MEAT_API UMeatSaveGame : public USaveGame
{
GENERATED_BODY()
public:
UMeatSaveGame();
UPROPERTY(VisibleAnywhere, Category = Basic)
uint32 SlotIndex;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Basic)
FSaveData SaveData;
};
I’m not in a position to test at the moment but my gut feeling is:
- Blueprints don’t like inheritance in struct (unless something has changed since I last checked). Get rid of the USTRUCT(BlueprintType) and replace with USTRUCT(). You might find that just removing USTRUCT altogether is required.
- GENERATE_BODY should be removed as your constructors are provided
Yeah, I can’t use any of the macros like USTRUCT() or GENERATED_BODY() either. So, that means I won’t be able to use it as a uproperty in some other class?
I don’t think you’d want to use FMeatSaveGameArchive as a UPROPERTY. I think you linked to this tutorial in an earlier question which shows it being used with MemoryWriter:
http://runedegroot.com/saving-and-loading-actor-data-in-unreal-engine-4/#comments
Basically, you don’t want to have FMeatSaveGameArchive as a member variable of anything, you just use it as part of the serialization / deserialization process.
But to use it in say, a function. I’d still need to declare the struct yes?
Declaring has nothing to do with the USTRUCT or any other property specifiers. You declare the struct just by creating it (Struct declaration - cppreference.com)
The USTRUCT etc exposes the struct to unreal and helps with memory management etc, but the absence of USTRUCT / UCLASS / UFUNCTION doesn’t normally stop you using it as you’d expect within normal C++. So if you wanted to create a FMeatSaveGameArchive variable within a function, you can do so. If you want to pass it around to other functions either as a value type or reference then you can also do that. The only thing you might need to watch out for is memory management.
Basically, think of it like a normal member variable. You don’t have to use UPROPERTY(), but if you don’t then you just need to be a little more careful.
Cool. I wanted to make sure that was the case. Thanks for the responses 