# How to create DataAsset with C++ from BluePrint class

**URL:** <https://forums.unrealengine.com/t/how-to-create-dataasset-with-c-from-blueprint-class/211029>\
**Category:** Editor Scripting\
**Tags:** unreal-engine\
**Created:** [March 26, 2021, 5:55am UTC](https://forums.unrealengine.com/t/how-to-create-dataasset-with-c-from-blueprint-class/211029 "2021-03-26T05:55:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy\_rst](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andy\_rst](https://forums.unrealengine.com/u/Andy_rst)\
**Post date:** [March 26, 2021, 5:55am UTC](https://forums.unrealengine.com/t/how-to-create-dataasset-with-c-from-blueprint-class/211029/1 "2021-03-26T05:55:51Z")

</div>

Hi

Here is some problem with saving object that created from BluePrint class.

**What i have:**  
Blueprint DataAseet inherited from UDataAsset.

**What i need:**  
Create with C++ same type as my blue print DataAsset object and save to the disk. As same way as inside of UE Editor Misc-\>Create Data asset.

**The Problem:**  
After asset was created, i have open asset and try to save once again with editor Save icon. Error: TestingAsset.uasset cannot be saved as it has only been partially loaded

In fact on the disk is not my DataAsset class, it’s UDataAsset.

**Question:**  
What proper way to create object from my blue print class? I have no class definition in C++.

```auto

// My Blue Print Data Asset class
FString AssetName("/Game/Glass/GlassCombined/DA_TBGlass_Base.DA_TBGlass_Base_C");

UClass* Result = FindObject<UClass>(ANY_PACKAGE, *AssetName);

FString AssetPath = TEXT("../../../../../Projects/PuzzleConstructor3/Content/Dev/");
FString PackagePath = TEXT("/Game/Dev/TestingAsset");

// Create package
UPackage *Package = CreatePackage(nullptr, *PackagePath);
Package->SetFlags(RF_Standalone | RF_Public);

// Create object
auto Test = NewObject<UDataAsset>(Package, Result, *FString("TestingAsset"), EObjectFlags::RF_Public | EObjectFlags::RF_Standalone | RF_Transactional);
FAssetRegistryModule::AssetCreated(Test);

// Save to the disk
bool bSuccess = UPackage::SavePackage(Package, Test, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone, *FilePath, GWarn, nullptr, true, true, NULL);

```

 ![image_216637.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/9/d9929c478b9e953bd7717fa1f8417ae7f43476ce.jpeg)

---

<div class="post-metadata">

**Author:** ![Andy\_rst](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andy\_rst](https://forums.unrealengine.com/u/Andy_rst)\
**Post date:** [March 26, 2021, 6:47pm UTC](https://forums.unrealengine.com/t/how-to-create-dataasset-with-c-from-blueprint-class/211029/2 "2021-03-26T18:47:52Z")

</div>

Solved. Working code:

```auto

FString AssetName2("/Game/Glass/GlassCombined/DA_TBGlass_Base.DA_TBGlass_Base_C");

auto Result = StaticLoadClass(UPrimaryDataAsset::StaticClass(), nullptr, *AssetName2, nullptr, LOAD_None, nullptr);

if (Result != nullptr)
{

FString PackagePathNew = TEXT("/Game/Dev/TestingAsset2");
UPackage *PackageNew = CreatePackage(nullptr, *PackagePathNew);

UObject* Obj = NewObject<UPrimaryDataAsset>(PackageNew, Result, *FString("TestingAsset2"), EObjectFlags::RF_Public | EObjectFlags::RF_Standalone);
FAssetRegistryModule::AssetCreated(Obj);

if (Obj != nullptr)
{
FString const PackageName = PackageNew->GetName();
FString const PackageFileName = FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension());

UPackage::SavePackage(PackageNew, NULL, RF_Public | RF_Standalone, *PackageFileName , GError, nullptr, false, true, SAVE_NoError);
Obj->MarkPackageDirty();
PackageNew->SetDirtyFlag(true);
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Load class is failed!"));
}

```

---

<div class="post-metadata">

**Author:** ![Babymaster3000](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Babymaster3000](https://forums.unrealengine.com/u/Babymaster3000)\
**Post date:** [July 22, 2023, 3:32pm UTC](https://forums.unrealengine.com/t/how-to-create-dataasset-with-c-from-blueprint-class/211029/3 "2023-07-22T15:32:07Z")

</div>

Another nifty way of doing this is using FEditorFileUtils::SaveAssetAs:  
[https://docs.unrealengine.com/4.27/en-US/API/Editor/UnrealEd/FEditorFileUtils/SaveAssetsAs/](https://docs.unrealengine.com/4.27/en-US/API/Editor/UnrealEd/FEditorFileUtils/SaveAssetsAs/)

Worked like a charm on the first try for me…
