I’m trying to rename an asset in UE 4.27.2 with code like:
// asset: UObject of the asset to rename
// newName: name string like "Snowman"
FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools");
UObject* uObject = asset.GetAsset();
TArray<FAssetRenameData> AssetsAndNames;
const FString PackagePath = FPackageName::GetLongPackagePath(uObject->GetOutermost()->GetName());
const FString NewName(UTF8_TO_TCHAR(newName));
new(AssetsAndNames) FAssetRenameData(uObject, PackagePath, NewName);
return AssetToolsModule.Get().RenameAssets(AssetsAndNames)
The IAssetTools::RenameAssets()
method returned true but the asset name in content browser didn’t change and I get error message in output log like:
LogPackageName: Error: DoesPackageExist: DoesPackageExist FAILED: 'Snowman' is not a standard unreal filename or a long path name. Reason: Path should start with a '/'
If I change the string variable newName to the full path starts with a ‘/’,the IAssetTools::RenameAssets()
method failed with following error message:
/Game/Snow - /Game/Snow to /Game/Game/Snowman.Game/Snowman: Name may not contain the following characters: /
It seems like some part of logic in IAssetTools::RenameAssets()
require the newName to starts with ‘/’ and another part of logic require the newName not to contain ‘/’.
Is this an engine bug?