Unable to edit the build settings on a static mesh from C++

I’m trying to access the “Use High Precision Tangent Basis” variable (as shown below in the Editor) but from C++, when I spawn an Actor tagged with “highPrecision” into the level.

I’ve found a way to access the static mesh build settings through [FStaticMeshSourceModel:][2]

bool result = newMeshComponent->SetStaticMesh(LoadMeshFromPath(FName(*meshPath)));

if (result)
{
   if (setHighPrecision)
   {
      UStaticMesh* precisionMesh = newMeshComponent->GetStaticMesh();
      FStaticMeshSourceModel& srcModel = precisionMesh->SourceModels[0];
      srcModel.BuildSettings.bUseHighPrecisionTangentBasis = true;
   }
}

I’ve tried to find a way to “save” this setting as you would in the Editor, and scoured the docs, but no matter what I try, the static mesh never has high precision tangents applied.

Am I on the right track here? Would appreciate any suggestions! Thanks,

1 Like

Did you ever find a solution to this?

Hi , yes I did actually. As the code above is being run through a commandlet inside a plugin I can just put the block between #if WITH_EDITOR and #endif and then save the mesh using:

UPackage* meshPackage = mesh->GetOutermost();

FString meshPackageFileName = FPackageName::LongPackageNameToFilename(meshPackage->GetPathName(),
                                                                                     FPackageName::GetAssetPackageExtension());

UPackage::SavePackage(meshPackage, nullptr, RF_Standalone, *meshPackageFileName);

Memory is slightly hazy, but I may also have had to include something like

#if WITH_EDITOR
    "UnrealEd"
#endif

in the dependencies inside my plugin’s Build.cs file.

Hope that helps!

1 Like

Nice! Thank you !