Announcement

Collapse
No announcement yet.

Static Mesh property disappears after save and close Unreal

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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:
    Click image for larger version  Name:	Blutility.PNG Views:	1 Size:	66.6 KB ID:	1535997
    Before Blutility:
    Click image for larger version  Name:	BeforeBlutility.PNG Views:	1 Size:	3.6 KB ID:	1535994
    After Blutility:
    Click image for larger version  Name:	AfterBlutility.PNG Views:	1 Size:	25.0 KB ID:	1535995
    After re-open project:
    Click image for larger version  Name:	AfterClose.PNG Views:	1 Size:	6.1 KB ID:	1535996

    Code:
    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.
    Last edited by OrsHerrero; 10-05-2018, 09:17 AM. Reason: blutility

    #2
    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.

    Click image for larger version

Name:	giphy.gif
Views:	2
Size:	491.6 KB
ID:	1536049

    Comment

    Working...
    X