# Rename assets in C++ from plugin

**URL:** <https://forums.unrealengine.com/t/rename-assets-in-c-from-plugin/320123>\
**Category:** Plugins\
**Tags:** rename, unreal-engine, Plugins, question, CPP\
**Created:** [May 29, 2015, 1:53pm UTC](https://forums.unrealengine.com/t/rename-assets-in-c-from-plugin/320123 "2015-05-29T13:53:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![RenovatioNova](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RenovatioNova](https://forums.unrealengine.com/u/RenovatioNova)\
**Post date:** [May 29, 2015, 1:53pm UTC](https://forums.unrealengine.com/t/rename-assets-in-c-from-plugin/320123/1 "2015-05-29T13:53:34Z")

</div>

Hello!

I have created a plugin for UE4. The main puprose of it is to rename assets inside project due to some external logic. I am using next code, but instead of renaming I get two similar assets with same names.

I am renaming from TestImage1 to TestImage2. Result is on the screenshot.

```
// Get the asset "TestImage1"
FAssetRegistryModule& AssetRegistryModule = FModuleManager::GetModuleChecked<FAssetRegistryModule>("AssetRegistry");
FAssetData XAssetData = AssetRegistryModule.Get().GetAssetByObjectPath(TEXT("/Game/TestImage1"));
UObject* Asset = XAssetData.GetAsset();
// Rename "TestImage1" into "TestImage2"
RenameAsset(Asset, TEXT("TestImage2"));

// Renaming method
void StandAloneModule::RenameAsset(UObject* Asset, const FString& NewName)
{
	FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools");
	TArray<FAssetRenameData> AssetsAndNames;
	const FString PackagePath = FPackageName::GetLongPackagePath(Asset->GetOutermost()->GetName());
	new(AssetsAndNames)FAssetRenameData(Asset, PackagePath, NewName);
	AssetToolsModule.Get().RenameAssets(AssetsAndNames);

	FAssetRegistryModule::AssetRenamed(Asset, TEXT("/Game/TestImage1"));
	Asset->MarkPackageDirty();
	Asset->GetOuter()->MarkPackageDirty();
}

```

 ![44549-2015-05-29_17h30_29.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/d/1/0d1a8f52f41ab43e4d27ee057691057a36a11e3f.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [May 29, 2015, 2:13pm UTC](https://forums.unrealengine.com/t/rename-assets-in-c-from-plugin/320123/2 "2015-05-29T14:13:12Z")

</div>

Hi RenovatioNova,

I’ve never tried to do this myself, but I believe the reason that it isn’t changing in the editor is due to the editor having two different names for most things, maybe 3. Normally there is the actual name of the variable or asset, then there is a friendly name and/or a display name. I’m not sure if DisplayName or FriendlyName is something than can be set for these assets, but it could be something similar to change the name of the asset in the editor itself.

Hope this helps

---

<div class="post-metadata">

**Author:** ![RenovatioNova](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RenovatioNova](https://forums.unrealengine.com/u/RenovatioNova)\
**Post date:** [May 29, 2015, 2:29pm UTC](https://forums.unrealengine.com/t/rename-assets-in-c-from-plugin/320123/3 "2015-05-29T14:29:07Z")

</div>

Thank you for a quick response!  
But why do duplicates appear? The sequence was next:

1. Only one TestImage1 asset in folder
2. Call to rename method
3. Second asset appear in folder (and first does not disapper)

I have copied renaming code from ContentBrowserUtils::RenameAsset from UnrealEngine/Engine/Source/Editor/ContentBrowser/Private/ContentBrowserUtils.cpp.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [June 1, 2015, 7:12pm UTC](https://forums.unrealengine.com/t/rename-assets-in-c-from-plugin/320123/4 "2015-06-01T19:12:02Z")

</div>

Hi RenovatioNova,

I actually managed to reproduce the issue itself without your plugin and simply renaming assets in the editor. It seems like it is an issue with the renaming itself and not your plugin, since you are copying the same code. I’ve reported it in our database. It’s possible that it is by design, as the code isn’t intended to be used in the way that you’re using it, but it is possible that it will be fixed. For your reference, the bug number is UE-16437. I’ll be sure to update you with any information that surfaces about this issue.

Have a nice day

---

<div class="post-metadata">

**Author:** ![RenovatioNova](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RenovatioNova](https://forums.unrealengine.com/u/RenovatioNova)\
**Post date:** [June 2, 2015, 10:07am UTC](https://forums.unrealengine.com/t/rename-assets-in-c-from-plugin/320123/5 "2015-06-02T10:07:37Z")

</div>

Thank you very much for a quick response! Is there any kind of workaround? My task is: rename/move/create/delete assets (saving all references when possible inside project) due to some external logic.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [June 2, 2015, 1:03pm UTC](https://forums.unrealengine.com/t/rename-assets-in-c-from-plugin/320123/6 "2015-06-02T13:03:08Z")

</div>

Other than using some different code, which I’m unsure of exactly what you need to do due to my lack in the development of plugins, I can’t think of anything that you could use as a workaround.

---

<div class="post-metadata">

**Author:** ![F1nik](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@F1nik](https://forums.unrealengine.com/u/F1nik)\
**Post date:** [September 13, 2016, 2:48pm UTC](https://forums.unrealengine.com/t/rename-assets-in-c-from-plugin/320123/7 "2016-09-13T14:48:38Z")

</div>

Hi,

This plugin (MORT) will help you to easy rename actors\objects in the World Outliner and Content Browser without bugs:  
[https://www.unrealengine.com/marketplace/multi-objects-renaming-tool](http://bit.ly/mort_ue4marketplace_br)

this is the youtube video: [https://youtu.be/UhEdy13AA-k](http://bit.ly/mort2_youtube_uef)

Features:

- Find and replace
- Rename and Numerate
- Prefix
- Suffix

---

<div class="post-metadata">

**Author:** ![Deus0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deus0](https://forums.unrealengine.com/u/Deus0)\
**Post date:** [February 1, 2017, 2:41am UTC](https://forums.unrealengine.com/t/rename-assets-in-c-from-plugin/320123/8 "2017-02-01T02:41:07Z")

</div>

This still hasn’t been fixed on unreals side. Copying still bugged, it creates a duplicate, doesn’t rename the ID only the file. Then unreal has issues because there are 2 files with the same ID. (the display name)

---

<div class="post-metadata">

**Author:** ![F1nik](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@F1nik](https://forums.unrealengine.com/u/F1nik)\
**Post date:** [February 1, 2017, 8:02am UTC](https://forums.unrealengine.com/t/rename-assets-in-c-from-plugin/320123/9 "2017-02-01T08:02:43Z")

</div>

Did you try the MORT plugin? It does not has issues that you mentioned.

---

<div class="post-metadata">

**Author:** ![kakyoism](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kakyoism](https://forums.unrealengine.com/u/kakyoism)\
**Post date:** [April 20, 2019, 8:39am UTC](https://forums.unrealengine.com/t/rename-assets-in-c-from-plugin/320123/10 "2019-04-20T08:39:44Z")

</div>

Do you have new clues on this issue? I got the same problem using the Python scripting, obviously a binding to what you’ve been using.

---

<div class="post-metadata">

**Author:** ![user\_4d9b0a58e88575d4b40f7e7f518ed36a0f7de0e6d464be8ce8a73c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@user\_4d9b0a58e88575d4b40f7e7f518ed36a0f7de0e6d464be8ce8a73c](https://forums.unrealengine.com/u/user_4d9b0a58e88575d4b40f7e7f518ed36a0f7de0e6d464be8ce8a73c)\
**Post date:** [November 10, 2023, 3:54am UTC](https://forums.unrealengine.com/t/rename-assets-in-c-from-plugin/320123/11 "2023-11-10T03:54:37Z")

</div>

After waiting for the asset to load, using UEditorAssetSubsystem::RenameAsset worked.

```auto
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");

if (AssetRegistryModule.Get().IsLoadingAssets())
{
	AssetRegistryModule.Get().OnFilesLoaded().AddRaw(this, &RenameAsset);
	return;
}

RenameAsset();

```

```auto
void RenameAsset()
{
	auto editorAssetSubsystem = GEditor->GetEditorSubsystem<UEditorAssetSubsystem>();
	editorAssetSubsystem->RenameAsset(oldPath, newPath);
}

```
