Spent probably 2 whole days on this topic, and digged very deep into the API doc, but still couldn’t get asset renaming working with the Epic Python Scripting plugin.
import unreal as ue ar = ue.AssetRegistryHelpers.get_asset_registry() path = '/Game/Path/To/MyAsset' new_path = '/Game/Path/To/MyNewAsset' ad = ar.get_asset_by_object_path(path) rnd = ue.AssetRenameData(asset=ad.get_asset(), new_package_path='/Game/Path/To', new_name='MyNewAsset') rnds = ue.Array(ue.AssetRenameData) rnds.append(rnd) at = ue.AssetToolsHelpers().get_asset_tools() ue.EditorAssetLibrary.save_asset(path, only_if_is_dirty=False) ue.load_asset(path) at.rename_assets(rnds) ue.EditorAssetLibrary.save_asset(new_path, only_if_is_dirty=False)
This code keeps giving me errors:
DataValidation: Error: /Game/Path/To/MyNewAsset contains invalid data. DataValidation: Error: Data validation FAILED. Files Checked: 1, Passed: 0, Failed: 1, Skipped: 0, Unable to validate: 0
I got the idea that in Unreal a bunch of things can share the same name. So I expect that renaming is not just a string manipulation but involves tracing and dependency tracking …
But this workflow is crazy.
I had to resort to the 20tab Python plugin on github, and the following code does the trick for me.
import unreal_engine as ue assets = ue.get_selected_assets() for a in assets: old_name = a.get_name() full_name = a.get_full_name() full_path = full_name.split(' ', 1) asset_path = full_path.split('.', 1) a.save_package() ue.rename_asset(full_path, 'MyNewAsset') a.get_outer().set_name('/Game/Path/To/MyNewAsset') a.save_package()
Still quite cumbersome IMO, but at least it gets the job done.
Am I missing something in the Epic Python API or is it just such a daunting task to rename?
P.S., I’m fairly new to both scripting APIs.