Hey folks!
I wrote a custom AssetManager class for a project where we don’t want to modify assets in a given folder. It basically checks the path that is being saved and if the asset has a read-only
flag set on its metadata, and sets the RF_TRANSIENT flag to it . The only property it allows to change is the metadata (the read-only
flag has to come from somewhere after all). It looks like this:
#include "LibAssetManager.h"
#include "UObject/ObjectSaveContext.h"
#include "EditorAssetLibrary.h"
#define READONLY_TAG "is_readonly"
#define READONLY_TAG_VALUE "True"
#define RESTRICTED_FOLDER "Restricted_Folder"
#define METADATA_PROPERTY "PackageMetaData"
void ULibAssetManager::OnObjectPreSave(UObject* Object, FObjectPreSaveContext SaveContext) {
// Get path to the asset that is being saved
FString objectPath = *Object->GetPathName();
UE_LOG(LogTemp, Display, TEXT("Saving path: %s"), *objectPath);
// Check if it is within the Library
if (objectPath.Contains(RESTRICTED_FOLDER)) {
// Get the readOnly flag
FString isReadOnly = UEditorAssetLibrary::GetMetadataTag(Object, READONLY_TAG);
// If the readOnly flag is set and we are NOT just changing the asset metadata, do not save the asset
if (isReadOnly == READONLY_TAG_VALUE && !objectPath.Contains(METADATA_PROPERTY)) {
UE_LOG(LogTemp, Display, TEXT("Is in library with read-only flag, will not save %s"), *objectPath);
Object->SetFlags(RF_Transient);
}
}
return;
}
This was working on Unreal 5.3.1. But after upgrading to 5.3.2, no asset is saved on the restricted folder anymore. My guess is that the TRANSIENT flag isn’t doing what I expect and is instead marking the asset for deletion instead of stopping the serialization. What would be the best way to stop serialization in this case?