Download

Static Mesh property disappears after save and close Unreal

Context:
I’m working in a plugin to add metadata to static meshes. For this, I have created a blutility to read asset metadata and assign a created subclass of AssetUserData to the meshes.

Problem:
Everything works fine, but when I save the project and close it, information disappears from modified static meshes.

Blutility:


Before Blutility:

After Blutility:

After re-open project:


bool UMODUtilities::SetAssetUserData(UObject * Object, UMODUserData* MODUserData)
{
    if (Object)
    {

    }
    else
    {
        UE_LOG(LogTemp, Error, TEXT("SetAssetUserData failed: Object is null."));
        return false;
    }

    UMODUserData* newMODUserData = NewObject<UMODUserData>();

    if (MODUserData)
    {

        newMODUserData->MODData = MODUserData->MODData;
    }
    else
    {
        UE_LOG(LogTemp, Error, TEXT("SetAssetUserData failed: MODUserData is null."));
    }

    //Test if Object is a mesh
    if (UStaticMesh* inMesh = Cast<UStaticMesh>(Object))
    {
        inMesh->AddAssetUserData(newMODUserData);

        return true;
    }
    else if (UMaterialInterface* inMaterial = Cast<UMaterialInterface>(Object))
    {
        inMaterial->AddAssetUserData(newMODUserData);
        return true;
    }
    UE_LOG(LogTemp, Error, TEXT("FBXMetadataToMODData failed: Object isn't mesh nor material."));
    return false;
}

Additional information:

I have try to add Transactions to the function but doesn’t change anything.

I have discovered that my error is when I create the newobject of the class “UMODUserData* newMODUserData = NewObject<UMODUserData>();” I don’t provide the outer, so the solution is: “UMODUserData* newMODUserData = NewObject<UMODUserData>(Object)” and that’s it.

One complete day figuring out how to solve it and it was just a word.

giphy.gif