I want to save data in a custom UDataAsset (which is not supposed to be edited in editor) and if I observed correctly only vars which have the UPROPERTY macro will be saved in such an asset.
For example if I have an custom UDataAsset like following:
UCLASS()
class MY_API USizeTDataAsset: public UDataAsset
{
GENERATED_BODY()
public:
size_t m_Size;
UPROPERTY()
int m_SizeInt;
};
Create and set it with following:
// get asset tool
IAssetTools& AssetTools = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools").Get();
// create factory
UDataAssetFactory* Factory = NewObject<UDataAssetFactory>();
// create asset
USizeTDataAsset* Asset = Cast<USizeTDataAsset>(AssetTools.CreateAsset(fileName, *outputPath, USizeTDataAsset::StaticClass(), Factory));
Asset->m_Size = 11;
Asset->m_SizeInt = 11;
And load it like so:
USizeTDataAsset* DataAsset = LoadObject<USizeTDataAsset>(nullptr, TEXT("PATH_TO_ASSET"), nullptr);
DataAsset->m_Size
will be 0 (unset) and DataAsset->m_SizeInt
will be 11.
I know unreal has a lot of data types which are supported by UPROPERTY and converting a size_t to int would be pretty easy, but I am have a lot more unsupported datatypes (like FXxHash128, std::vector, custom structs and more). Converting them all to supported types would be annoying and unefficient.
TLDR:
- Is there a way to store data types which are not supported by the UPROPERTY macro in a DataAsset?
- Or is there a way to add support for classes with the UPROPERTY macro?
- Or is there a better solution for saving data which isn’t supposed to be edited in editor (and is automatically packaged by unreal without the need to add a extra Non-Asset packaging directory)?