x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Rename assets in C++ from plugin

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();
 }


alt text

Product Version: UE 4.7
Tags:
more ▼

asked May 29 '15 at 01:53 PM in C++ Programming

avatar image

RenovatioNova
117 6 11 17

avatar image F1nik Sep 13 '16 at 02:48 PM

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

this is the youtube video: https://youtu.be/UhEdy13AA-k

Features:

  • Find and replace

  • Rename and Numerate

  • Prefix

  • Suffix

avatar image Deus0 Feb 01 '17 at 02:41 AM

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)

avatar image F1nik Feb 01 '17 at 08:02 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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

Matthew Clark

more ▼

answered May 29 '15 at 02:13 PM

avatar image RenovatioNova May 29 '15 at 02:29 PM

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.

avatar image kakyoism Apr 20 '19 at 08:39 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

Matthew Clark

more ▼

answered Jun 01 '15 at 07:12 PM

avatar image RenovatioNova Jun 02 '15 at 10:07 AM

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.

avatar image Matthew J Jun 02 '15 at 01:03 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question