Issues with Saving Texture with UEditorLoadingAndSavingUtils::SavePackages

I have an usual issue where I try to serialize a texture, it supposedly successfully writes to disk but when reloading the asset it the old version shows up.

I’m working on a tool in editor (5.4.4) that requires working with render targets. Since render targets themselves cannot be saved, my approach is to load a texture from the content browser, write to it, then save it again. The action is called through a macro’d function in one of the tools. The code seemingly runs without problems, the content browser thumbnail updates, the texture shows the changes, in the file explorer the ‘Date Modified’ gets updated to the current time. However once the editor is closed the changes are lost. Below I have a video to better showcase my problem.

Thank you in advance.

Video

  • Below I have a video showcasing my problem. I try to write a single pixel to a 32 x 32 texture.
  • Standard 2d texture (default compression, no mipmaps, neverstream = true, XY clamped)
  • Code is afterwards…
    texturesave

Code

// Creating the name of the atlas texture.
// The atlas texture name is the same as level but with "T_" prefix.
// Used in loading & packaging.
const FString AtlasNameContentPath = FilePath + "T_" + (GetWorld()->GetMapName().RightChop(2)); 
																									
																									
UTexture2D* AtlasTexture = Cast<UTexture2D>(StaticLoadObject(UTexture2D::StaticClass(),  
	                                      nullptr, *AtlasNameContentPath, nullptr,
	                                      ELoadFlags::LOAD_RegenerateBulkDataGuids));
if (!AtlasTexture)
{
                UE_LOG(LogTemp, Error, TEXT("FUNCTION: SaveCurrentCorruption(), atlas texture could not be loaded."));
		return;
}
if (!AtlasTexture->GetPlatformData() || AtlasTexture->GetPlatformData()->Mips.Num() == 0)
{
		UE_LOG(LogTemp, Error, TEXT("FUNCTION: SaveCurrentCorruption(), invalid bulk data."));
		return;
}
	
FTexture2DMipMap& AtlasMipMap = AtlasTexture->GetPlatformData()->Mips[0];
void* AtlasDataRaw = AtlasMipMap.BulkData.Lock(LOCK_READ_WRITE);
FColor* AtlasData = static_cast<FColor*>(AtlasDataRaw);
	
// Single pixel 
AtlasData[0] = Color;
	
AtlasMipMap.BulkData.Unlock();
AtlasTexture->UpdateResource();
	
// Creating & saving texture
UPackage* AtlasPackage = AtlasTexture->GetPackage();
if (!AtlasPackage || !AtlasPackage->MarkPackageDirty())
{
	       UE_LOG(LogTemp, Error, TEXT("FUNCTION: Save CurrentCorruption(), failed to create package."));
		return;
}
	
UEditorLoadingAndSavingUtils::SavePackages({AtlasPackage}, false);