Download

Dataprep: setting the destination path when using CreateAsset

I’ve created a blueprint based on the new DataprepEditingOperation class and added it to a Dataprep asset, imported a datasmith file and it populated the preview tree no problem. When I try to create a material asset using CreateAsset the asset is previewed as being in Engine/DataprepEditor/Transient/… I assume this is the temporary location the assets are mapped to by the dataprep system. The question is how do I set the path so that the assets are created in the right place when I commit the dataprep.

So for textures I’m able to use the the GetAssetTools ImportAssetAutomated and then add the object to the dataprep using addAsset. The asset is re-pathed on add, no big deal. This seems like a messy way to have to do things but it works.

So when I try to take the same basic approach with GetAssetTools CreateAsset (seems to work through python from what I’ve seen in the forums)


I feel like I’m missing something or maybe its just that these functions were exposed for python and it just hasn’t been tested for blueprints yet. Is there some way of creating factories in blueprints I havn’t found.

Anyway I’ve created a work around for now that works but seems mad to have to do.


UMaterialInterface* UMyBlueprintFunctionLibrary::CreateMaterialAsset(const FString& AssetName, const FString& PackagePath)
{
    const FString PackageName = UPackageTools::SanitizePackageName(PackagePath + TEXT("/") + AssetName);

    UPackage* Package = CreatePackage(nullptr, *PackageName);

    EObjectFlags Flags = RF_Public | RF_Standalone | RF_Transactional;
    // Verify that the material could be created in final package
//    FText FailReason;
//    if (!FDatasmithImporterUtils::CanCreateAsset<UMaterialInterface>(Package, AssetName, FailReason))
//    {
    //    AssetsContext.ParentContext.LogError(FailReason);
//        return nullptr;
//    }


    UMaterialFactoryNew* MatFact = NewObject<UMaterialFactoryNew>();
    MatFact->AddToRoot();

    UMaterial* UnrealMaterial = (UMaterial*)MatFact->FactoryCreateNew(UMaterial::StaticClass(), Package, FName(*AssetName), Flags, nullptr, GWarn);
    UnrealMaterial->MarkPackageDirty();
    FAssetRegistryModule::AssetCreated(UnrealMaterial);
    Package->SetDirtyFlag(true);
    MatFact->RemoveFromRoot();

    return UnrealMaterial;
}


Then I create the material, build it’s contents and use addAsset to allow dataprep to create it properly


The package path I set to “/Engine/DataprepEditor/Transient/” to match the assets created by dataprep, not sure if this is right.

I know I’m jumping the gun on these features and they are clearly still experimental but it does seem like we are meant to be able to do this in the current version of dataprep I just feel like I’m missing a trick.