Unable to load UDataAsset after editor restart

Hi, I’m pretty new to UE and I’m trying to undestand how UPackages work.and specifically the ::SavePackage() function.
What I want to do is:

  1. Define a UDataAsset in C++ (Plain Old Data)
  2. Populate it manually in the editor and Save it
  3. Feed it as input to a function in C++ that produces an output
  4. Save the output and a copy of the input from C++ to another UDataAsset visible from the editor
  5. Feed that resulting UDataAsset to an Actor (by UPROPERTY drag and drop from the editor)

So far all is good until step 4.
The two UAssetData definitions

UCLASS()
class UInputData: public UDataAsset
{
	GENERATED_BODY()
public:
    UPROPERTY(EditAnywhere)
	uint16 some_int_var =  5000;

	UPROPERTY(EditAnywhere)
	float  some_float_var= 0.10f;
};

UCLASS()
class UCombinedResult : public UDataAsset
{
	GENERATED_BODY()
public:
	UPROPERTY(VisibleAnywhere)
	UInputData* InputData;

	UPROPERTY(VisibleAnywhere)
	UCustomData CustomData;
};

And the c++ class that handles the generation of the output:

UCLASS()
class ATransformer : public AActor
{
public:
    UPROPERTY(EditAnywhere)
    UInputData* InputData;
private:
    UCombinedResult* Output;
    UPackage* Package;
    UCustomData MyCustomData;
public:
    void Init()
    {
        // Create the Package
        FString PackageName = TEXT("/Game/Generated/MyOutput");
        Package = CreatePackage(nullptr, *PackageName);
        Package->FullyLoad();
        Output = NewObject<UCombinedResult >(Package, TEXT("MyOutput"), RF_Public | RF_Standalone | RF_MarkAsRootSet);

        if (InputData == nullptr) // Creates the default object
            InputData = NewObject<UInputData>(Package, TEXT("InputData"));
        else // Duplicates the object but this time inside the package
            InputData = DuplicateObject<UInputData>(InputData, Package, TEXT("InputData"));

        Package->MarkPackageDirty();
    }
    void Process()
    {
        MyCustomData = DoWork(InputData);
    }
    void Export()
    {
        Output->CustomData = MyCustomData;
        Output->InputData = InputData;

        Package->MarkPackageDirty();
        FAssetRegistryModule::AssetCreated(Output);

        FString PackageName = TEXT("/Game/Generated/MyOutput");
        FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension());
        UPackage::SavePackage(Package, Output, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone, *PackageFileName, GError, nullptr, true, true, SAVE_NoError);
    }
protected:
    void BeginPlay()
    {
        Init();
        Process();
        Export();
    }
};

So I basically create the new Output object and mark it as RF_Standalone and RF_Public , that to my understanding makes it visible to the editor and marks it as the “head” of the package

The SavePackage documentation says:

Save one specific object (along with any objects it references contained within the same Outer) into an Unreal package.

The Save operation is actually successful and I am able to see in the editor an asset of Type UCombinedResult and if I open it it correctly shows that it references a new UInputData object (not the one I gave to it as input but a copy of it not found anywhere else in the editor). My UCustomData object shows up but its broken (but thats probably due to improper serialization on my part, but that is another problem).

The result is that as long as I keep the editor alive I can use my UCombinedResult (output object) just fine and it actually holds the data that I need, but when I shut down and restart, even though I can see the .uasset file being created in the file explorer, the UCombinedResult asset is there but it doesnt load.
If I double click it in the console appears this

LogLinker: Warning: Unable to load MyOutput with outer Package /Game/Generated/MyOutput because its class does not exist
LogUObjectGlobals: Warning: Failed to find object 'Object /Game/MapData/MyOutput.MyOutput'

Thanks to everyone that read though all this. Hope you can give me some explaination around Unreal Packages (and specifically saving them) since you kinda find them everywhere in the engine but the Official documentation has nothing about them.

Ok so I managed to make it work although I . The code is all fine, I didnt change anything but looking at the console messages that i reported:

LogLinker: Warning: Unable to load MyOutput with outer Package /Game/Generated/MyOutput because its class does not exist
LogUObjectGlobals: Warning: Failed to find object 'Object /Game/MapData/MyOutput.MyOutput'

you can see how the editor doesn’t even specify the right reference in the log: It’s looking for the class “Object” in the MyOutput package while it should be looking for the class “CombinedResult”. Of course there is no UObject in the package!
It’s almost as if the editor isn’t aware that a class that extends UDataAsset called UCombinedResult exists, even though if I try to create an UDataAsset from the editor it correctly gives me the option to select it and manually create an instance.

And even if I create an empty default instance of UCombinedResult from the editor and then close and reopen it, we get the same behavior with the aforementioned logs: class shows up but I cant open and I get the “Unable to load” error…

At this point I have no idea what is going with the UCombinedResult class, maybe since I created the file containing the declaration manually from the file explorer and not with the wizard in the editor it didn’t register?

So I copied and pasted all the code from UCombinedResult to an existing class that extends UDataAsset that I already had in the project (not sure if it was created manually or with the wizard) and now everything works.

Should this happen to someone else i would suggest to:

  1. Make sure that you add your source files from the Editor wizard.
  2. Try deleting the Intermediate and Binaries folders (I didn’t do it but could help)
  3. Try to change the name. The real name of the class that in this post I call UCombinedResult was UWorldInfo, maybe that was reserved (although I didnt get any errors whatsoever)
  4. Move the file to another folder. My original DataAsset was located in the /Public folder while this new one is in /Public/MapData.
1 Like