Object is not packaged error in C++

I’m trying to create a texture from raw color data then save to the disk. Here is the function for creating the texture but I’m receiving an error.

Fatal error: [File:D:\BuildFarm\buildmachine_++UE4+Release-4.11\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 1969] &nl;Object is not packaged: Texture2D Test&nl;

Also, any helpful information on how I would go about saving it would be greatly appreciated.

UTexture2D * UCreateTexture::LoadData(FString name, UObject* owner, int width, int height, TArray<FLinearColor> colorData)
{
    FCreateTexture2DParameters p = FCreateTexture2DParameters();
    p.bDeferCompression = false;
    p.bSRGB = true;
    p.bUseAlpha = true;
    TArray<FColor> data;
    for (FLinearColor lc : colorData)
    {
        FColor c = FColor();
        c.R = lc.R;
        c.G = lc.G;
        c.B = lc.B;
        c.A = 255;
        data.Add(c);
    }
    UTexture2D * tex = FImageUtils::CreateTexture2D(width, height, data, owner, name, EObjectFlags::RF_Transient, p);
    return tex;
}

bool UCreateTexture::LoadData(FString dest, int width, int height, TArray colorData)
{
TArray outBMP;
for (FLinearColor lc : colorData)
{
FColor c = FColor();
c.R = lc.R;
c.G = lc.G;
c.B = lc.B;
c.A = 255;
outBMP.Add(c);
}
TArray compressedBitmap;
FImageUtils::CompressImageArray(width, height, outBMP, compressedBitmap);
bool imageSavedOk = FFileHelper::SaveArrayToFile(compressedBitmap, *dest);
return imageSavedOk;
}

This answer is totally useless. It doesn’t explain what the problem was or how it was fixed.

3 Likes