AssetTools.RenameAssets() stumbles over itself moving assets

I’m simply trying to move a bunch of assets from one folder to another inside a commandlet. I’ve initialized the source control module and checked to ensure that it’s enabled (and all the perforce details in the log appear to be correct)

I do it something like this:

FAssetRenameData RenameData(asset, TargetPackagePath, asset->GetName());
 
FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools");
IAssetTools& AssetTools = AssetToolsModule.Get();
AssetTools.RenameAssets({RenameData});

The source file gets checked out (not marked for delete), the destination file gets created, but not marked for add.

The log also has some interesting lines:

FAssetRenameManager::AutoCheckOut: was not not able to auto checkout.This seems to happen despite the checkout succeeding?

SourceControl: Error: CommandMessage Command: Copy, Error: Can't clobber writable file D:\path\to\asset.uasset
Error: CommandMessage Command: Copy, Error: D:\path\to\asset.uasset - no file(s) to resolve.

This error is about the local file at the target location that it literally just created

Were there maybe some bugs in 5.4 that have been fixed in later versions, or is there some trick to using the function (or am I just making a big, obvious mistake somewhere)?

EDIT 26/05:

OK it looks like there are two problems here:

1 - This one is just a bit of a spurious error message:

Inside `FAssetRenameManager::AutoCheckOut`, the “success” code path spews out `LogAssetTools: Warning: FAssetRenameManager::AutoCheckOut: was not not able to auto checkout.` - basically, we have a warning, and a message with a double negative. I think this should be changed to “Display” (from “Warning”) and the message should probably be something like “Successfully checked out package %s”

2 - This is the more serious problem:

Inside `UEditorEngine::IsPackageValidForAutoAdding`, for some unexplained reason, you prevent commandlets from adding assets to source control (which also, unfortunately, includes moving and copying files) with a simple `!IsRunningCommandlet()` check. I commented out that part of the condition and my commandlet magically started working.

Why is it like this? Can we remove this check? Is this fixed in a more recent version of unreal?

Hi Daniel,

I don’t think we support the use case of populating changelists and committing them from commandlets. Honestly, UEditorEngine::IsPackageValidForAutoAdding has been this way since 2011 so I’m not sure of the exact reasoning for it being the way it is but I assume we have commandlets that create or save content that aren’t meant to be sent to source control.

Overall, automating asset renaming through a commandlet is just not a use case that we looked at. I believe you could launch the editor and run a Python script to do the renaming while the editor is actually running if you wanted to try a different approach.

If you want to go the commandlet route, I’m afraid I don’t have a solution for you other than if you figure out a way to do it cleanly without impacting the expectations of other commandlets, then we’d be happy to take your PR.

Thanks