RenameAssets

RenameAssets

#Overview

name: RenameAssets

This variable is created as a Console Variable (cvar).

It is referenced in 22 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of RenameAssets is to rename one or more assets in the Unreal Engine project. This function is part of the asset management system and is used across various subsystems and plugins within the Unreal Engine.

RenameAssets is primarily used by the AssetTools module, which is part of the core engine’s asset management system. It’s also utilized by several other subsystems and plugins, including:

  1. ControlRigEditor
  2. IKRigEditor
  3. BlueprintHeaderView
  4. DatasmithImporter
  5. AdvancedRenamer
  6. ToolPresetEditor
  7. DisplayClusterConfigurator
  8. EditorLevelUtils
  9. EditorAssetSubsystem
  10. InterchangeEngine

The value of this variable is typically set when calling the RenameAssets function, which takes an array of FAssetRenameData structures as input. Each structure contains information about the asset to be renamed, including the current asset, the new package path, and the new name.

RenameAssets often interacts with other asset management functions and variables, such as:

  1. AssetRegistryModule for checking asset loading status
  2. FAssetRenameData for storing rename information
  3. AssetTools module for performing the actual rename operation
  4. Various blueprint and structure editing utilities

Developers should be aware of several important aspects when using RenameAssets:

  1. Asset references: Renaming assets can break existing references in the project. Ensure all references are updated after renaming.
  2. Asset Registry: The operation may fail if the Asset Registry is still loading assets.
  3. Source control: Consider integrating with source control systems when renaming assets.
  4. Soft references: Update soft references after renaming assets using RenameReferencingSoftObjectPaths.

Best practices when using RenameAssets include:

  1. Perform renaming operations in batches when possible to improve performance.
  2. Always check the return value to ensure the rename operation was successful.
  3. Update any caches or references that might be affected by the rename operation.
  4. Consider using RenameAssetsWithDialog for user-facing operations to handle potential conflicts or issues.
  5. Be cautious when renaming assets that are part of a larger system or heavily referenced throughout the project.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Plugins/Animation/ControlRig/Source/ControlRigEditor/Private/EditMode/SControlRigBaseListWidget.h:91

Scope (from outer to inner):

file
class        class SControlRigBaseListWidget : public SCompoundWidget

Source code excerpt:

	void ExecuteAddFolder(const FString SelectedPath);
	FReply ExecuteDeleteFolderConfirmed();
	void ExecuteRenameAssets(const TArray<FAssetData> RenameAssets);
	bool CanExecuteRenameAssets(const TArray<FAssetData> RenameAssets) const;
	void ExecuteSaveAssets(const TArray<FAssetData> SelectedAssets);
	void ExecuteDeleteAssets(const TArray<FAssetData> SelectedAssets);
	void ExecutePastePose(UControlRigPoseAsset* PoseAsset);
	bool CanExecutePastePose(UControlRigPoseAsset* PoseAsset) const;
	void ExecuteSelectControls(UControlRigPoseAsset* PoseAsset);
	void ExecutePasteMirrorPose(UControlRigPoseAsset* PoseAsset);

#Loc: <Workspace>/Engine/Plugins/Animation/IKRig/Source/IKRigEditor/Private/RetargetEditor/IKRetargetBatchOperation.cpp:641

Scope (from outer to inner):

file
function     void UIKRetargetBatchOperation::OverwriteExistingAssets

Source code excerpt:

		FString CurrentAssetPath = NewAsset->GetPathName();
		TArray<FAssetRenameData> AssetsToRename = { FAssetRenameData(CurrentAssetPath, DesiredObjectPath) };
		AssetToolsModule.Get().RenameAssets(AssetsToRename);
	}
}

void UIKRetargetBatchOperation::NotifyUserOfResults(
	const FIKRetargetBatchOperationContext& Context,
	FScopedSlowTask& Progress) const

#Loc: <Workspace>/Engine/Plugins/Editor/BlueprintHeaderView/Source/BlueprintHeaderView/Private/HeaderViewClassListItem.cpp:205

Scope (from outer to inner):

file
function     void FHeaderViewClassListItem::OnRenameTextComitted

Source code excerpt:

				FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools");
				TArray<FAssetRenameData> AssetToRename = { FAssetRenameData(Blueprint, NewPath) };
				AssetToolsModule.Get().RenameAssets(AssetToRename);
				FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(Blueprint);
			}
		}
	}
}

#Loc: <Workspace>/Engine/Plugins/Editor/BlueprintHeaderView/Source/BlueprintHeaderView/Private/HeaderViewStructListItem.cpp:132

Scope (from outer to inner):

file
function     void FHeaderViewStructListItem::OnRenameTextComitted

Source code excerpt:

				FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools");
				TArray<FAssetRenameData> AssetToRename = { FAssetRenameData(Struct, NewPath) };
				AssetToolsModule.Get().RenameAssets(AssetToRename);
				FStructureEditorUtils::OnStructureChanged(Struct, FStructureEditorUtils::Unknown);
			}
		}
	}
}

#Loc: <Workspace>/Engine/Plugins/Enterprise/DatasmithImporter/Source/DatasmithImporter/Private/DatasmithConsumer.cpp:1919

Scope (from outer to inner):

file
namespace    DatasmithConsumerUtils
function     TArray<AActor*> MoveActorsToLevel

Source code excerpt:

		if (RenameData.Num() > 0)
		{
			AssetTools.RenameAssets(RenameData);

			// Fix soft references in level sequences and variants
			if(PackagesToCheck.Num() > 0)
			{
				AssetTools.RenameReferencingSoftObjectPaths(PackagesToCheck, ActorPathMapping);
			}

#Loc: <Workspace>/Engine/Plugins/Experimental/AdvancedRenamer/Source/AdvancedRenamer/Private/Providers/AdvancedRenamerAssetProvider.cpp:112

Scope (from outer to inner):

file
function     bool FAdvancedRenamerAssetProvider::ExecuteRename

Source code excerpt:


	IAssetTools& AssetTools = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools").Get();
	return AssetTools.RenameAssets({FAssetRenameData(Asset, PackagePath, NewName)});
}

#undef LOCTEXT_NAMESPACE

#Loc: <Workspace>/Engine/Plugins/Experimental/ToolPresets/Source/ToolPresetEditor/Private/Widgets/SToolPresetManager.cpp:1291

Scope (from outer to inner):

file
function     void SToolPresetManager::CollectionRenameEnded

Source code excerpt:

		RenameData[0].NewName = NewAssetName;
		RenameData[0].NewPackagePath = CollectionAsset.PackagePath.ToString();
		if(IAssetTools::Get().RenameAssets(RenameData))
		{
			if (UserSettings->EnabledPresetCollections.Contains(TreeEntry->CollectionPath))
			{
				UserSettings->EnabledPresetCollections.Remove(TreeEntry->CollectionPath);
				UserSettings->EnabledPresetCollections.Add(CollectionObject->GetPathName());
				UserSettings->SaveEditorConfig();

#Loc: <Workspace>/Engine/Plugins/Runtime/nDisplay/Source/DisplayClusterConfigurator/Private/DisplayClusterConfiguratorEditorSubsystem.cpp:114

Scope (from outer to inner):

file
function     bool UDisplayClusterConfiguratorEditorSubsystem::RenameAssets

Source code excerpt:

}

bool UDisplayClusterConfiguratorEditorSubsystem::RenameAssets(const TWeakObjectPtr<UObject>& InAsset, const FString& InNewPackagePath, const FString& InNewName)
{
	FAssetToolsModule& AssetToolsModule = FModuleManager::GetModuleChecked<FAssetToolsModule>(TEXT("AssetTools"));

	TArray<FAssetRenameData> RenameData;

	RenameData.Add(FAssetRenameData(InAsset, InNewPackagePath, InNewName));

#Loc: <Workspace>/Engine/Plugins/Runtime/nDisplay/Source/DisplayClusterConfigurator/Private/DisplayClusterConfiguratorEditorSubsystem.h:23

Scope (from outer to inner):

file
class        class UDisplayClusterConfiguratorEditorSubsystem : public UEditorSubsystem

Source code excerpt:

	UDisplayClusterConfigurationData* ReloadConfig(UDisplayClusterBlueprint* InBlueprint, const FString& InConfigPath);

	bool RenameAssets(const TWeakObjectPtr<UObject>& InAsset, const FString& InNewPackagePath, const FString& InNewName);

	bool SaveConfig(UDisplayClusterConfigurationData* InConfiguratorEditorData, const FString& InConfigPath);

	// Convert configuration to string
	bool ConfigAsString(UDisplayClusterConfigurationData* InConfiguratorEditorData, FString& OutString) const;
};

#Loc: <Workspace>/Engine/Source/Developer/AssetTools/Private/AssetRenameManager.cpp:241

Scope (from outer to inner):

file
function     bool FAssetRenameManager::RenameAssets

Source code excerpt:


/** Renames assets using the specified names. */
bool FAssetRenameManager::RenameAssets(const TArray<FAssetRenameData>& AssetsAndNames) const
{
	// If the asset registry is still loading assets, we cant check for referencers, so we must open the rename dialog
	FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
	if (AssetRegistryModule.Get().IsLoadingAssets())
	{
		UE_LOG(LogAssetTools, Warning, TEXT("Unable To Rename While Discovering Assets"));

#Loc: <Workspace>/Engine/Source/Developer/AssetTools/Private/AssetRenameManager.h:30

Scope (from outer to inner):

file
class        class FAssetRenameManager : public TSharedFromThis<FAssetRenameManager>

Source code excerpt:

public:
	/** Renames assets using the specified names. */
	bool RenameAssets(const TArray<FAssetRenameData>& AssetsAndNames) const;

	/** Renames assets using the specified names. */
	EAssetRenameResult RenameAssetsWithDialog(const TArray<FAssetRenameData>& AssetsAndNames, bool bAutoCheckout = false) const;

	/** Returns list of objects that soft reference the given soft object path. This will load assets into memory to verify */
	void FindSoftReferencesToObject(FSoftObjectPath TargetObject, TArray<UObject*>& ReferencingObjects) const;

#Loc: <Workspace>/Engine/Source/Developer/AssetTools/Private/AssetTools.cpp:2789

Scope (from outer to inner):

file
function     bool UAssetToolsImpl::RenameAssets

Source code excerpt:

}

bool UAssetToolsImpl::RenameAssets(const TArray<FAssetRenameData>& AssetsAndNames)
{
	return AssetRenameManager->RenameAssets(AssetsAndNames);
}

EAssetRenameResult UAssetToolsImpl::RenameAssetsWithDialog(const TArray<FAssetRenameData>& AssetsAndNames, bool bAutoCheckout)
{
	return AssetRenameManager->RenameAssetsWithDialog(AssetsAndNames, bAutoCheckout);
}

#Loc: <Workspace>/Engine/Source/Developer/AssetTools/Private/AssetTools.h:91

Scope (from outer to inner):

file
class        class UAssetToolsImpl : public UObject, public IAssetTools

Source code excerpt:

	virtual bool IsDiscoveringAssetsInProgress() const override;
	virtual void OpenDiscoveringAssetsDialog(const FOnAssetsDiscovered& InOnAssetsDiscovered) override;
	virtual bool RenameAssets(const TArray<FAssetRenameData>& AssetsAndNames) override;
	virtual EAssetRenameResult RenameAssetsWithDialog(const TArray<FAssetRenameData>& AssetsAndNames, bool bAutoCheckout = false) override;
	virtual void FindSoftReferencesToObject(FSoftObjectPath TargetObject, TArray<UObject*>& ReferencingObjects) override;
	virtual void FindSoftReferencesToObjects(const TArray<FSoftObjectPath>& TargetObjects, TMap<FSoftObjectPath, TArray<UObject*>>& ReferencingObjects) override;
	virtual void RenameReferencingSoftObjectPaths(const TArray<UPackage *> PackagesToCheck, const TMap<FSoftObjectPath, FSoftObjectPath>& AssetRedirectorMap) override;
	virtual TArray<UObject*> ImportAssetsWithDialog(const FString& DestinationPath) override;
	virtual void ImportAssetsWithDialogAsync(const FString& DestinationPath) override;

#Loc: <Workspace>/Engine/Source/Developer/AssetTools/Public/IAssetTools.h:376

Scope (from outer to inner):

file
class        class IAssetTools

Source code excerpt:

	/** Renames assets using the specified names. */
	UFUNCTION(BlueprintCallable, Category = "Editor Scripting | Asset Tools")
	virtual bool RenameAssets(const TArray<FAssetRenameData>& AssetsAndNames) = 0;

	/** Renames assets using the specified names. */
	UFUNCTION(BlueprintCallable, Category = "Editor Scripting | Asset Tools")
	virtual EAssetRenameResult RenameAssetsWithDialog(const TArray<FAssetRenameData>& AssetsAndNames, bool bAutoCheckout = false) = 0;

	/** Returns list of objects that soft reference the given soft object path. This will load assets into memory to verify */

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/EditorLevelUtils.cpp:253

Scope: file

Source code excerpt:

								else
								{
									AssetToolsModule.Get().RenameAssets(RenameData);
								}
							}
						}

						// Restore new level visibility to previous state
						if (!bLevelVisible)

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/EditorLevelUtils.cpp:272

Scope (from outer to inner):

file
function     int32 UEditorLevelUtils::CopyOrMoveActorsToLevel

Source code excerpt:

			for (TWeakObjectPtr<AActor> ActorPtr : FinalWeakMoveList)
			{
				// It is possible a GC happens because of RenameAssets being called so here we want to update the CopyPasteId only on reachable actors
				if (AActor* Actor = ActorPtr.Get(/*bEvenIfPendingKill=*/true))
				{
					check(Actor->CopyPasteId != INDEX_NONE);
					// Reset CopyPasteId on source actors 
					Actor->CopyPasteId = INDEX_NONE;
				}

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Subsystems/EditorAssetSubsystem.cpp:986

Scope (from outer to inner):

file
namespace    UE::EditorAssetUtils
function     bool RenameLoadedAsset

Source code excerpt:


		FAssetToolsModule& Module = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools");
		return Module.Get().RenameAssets(AssetToRename);
	}
}

bool UEditorAssetSubsystem::RenameLoadedAsset(UObject* SourceAsset, const FString& DestinationAssetPath)
{
	TGuardValue<bool> UnattendedScriptGuard(GIsRunningUnattendedScript, true);

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Subsystems/EditorAssetSubsystem.cpp:1074

Scope (from outer to inner):

file
function     bool UEditorAssetSubsystem::RenameDirectory

Source code excerpt:

		// Rename the assets
		FAssetToolsModule& Module = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools");
		if (!Module.Get().RenameAssets(AssetsToRename))
		{
			UE_LOG(LogEditorAssetSubsystem, Error, TEXT("RenameDirectory failed: Could not rename the assets."));
			return false;
		}
	}

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/UnrealEdSrv.cpp:1125

Scope (from outer to inner):

file
function     bool UUnrealEdEngine::Exec

Source code excerpt:

		}
	}
	else if (FParse::Command(&Str, TEXT("RenameAssets")))
	{
		FString SearchTermStr;
		if ( FParse::Value(Str, TEXT("Find="), SearchTermStr) )
		{
			FString ReplaceStr;
			FParse::Value(Str, TEXT("Replace="), ReplaceStr );

#Loc: <Workspace>/Engine/Source/Runtime/Interchange/Engine/Private/Tasks/InterchangeTaskParsing.cpp:238

Scope (from outer to inner):

file
function     void UE::Interchange::FTaskParsing::DoTask

Source code excerpt:

	};

	TMap<FString, FTaskParsingRenameInfo> RenameAssets;
	TSet<FString> CreatedTasksAssetNames; // Tracks for which asset name we have created a task so that we don't have 2 tasks for the same asset name
	TFunction<FGraphEventRef(FTaskData&)> CreateTasksFromData = [this, &AsyncHelper, &RenameAssets, &CreatedTasksAssetNames](FTaskData& TaskData)
	{
		LLM_SCOPE_BYNAME(TEXT("Interchange"));
		check(TaskData.Nodes.Num() == 1); //We expect 1 node per asset task

		const int32 SourceIndex = TaskData.SourceIndex;
		const UClass* const FactoryClass = TaskData.FactoryClass;

#Loc: <Workspace>/Engine/Source/Runtime/Interchange/Engine/Private/Tasks/InterchangeTaskParsing.cpp:273

Scope (from outer to inner):

file
function     void UE::Interchange::FTaskParsing::DoTask
lambda-function

Source code excerpt:

					const FString NameIndexString = FString::FromInt(NameIndex++);
					NewName = AssetFullPath + NameIndexString;
					FTaskParsingRenameInfo& RenameInfo = RenameAssets.FindOrAdd(AssetFullPath);
					RenameInfo.FactoryNode = FactoryNode;
					RenameInfo.OriginalName = AssetFullPath;
					RenameInfo.NewName = NewName;
					RenameInfo.SourceIndex = SourceIndex;
					FactoryNode->SetDisplayLabel(FactoryNode->GetDisplayLabel() + NameIndexString);
					if (FactoryNode->HasAttribute(UE::Interchange::FBaseNodeStaticData::AssetNameKey()))

#Loc: <Workspace>/Engine/Source/Runtime/Interchange/Engine/Private/Tasks/InterchangeTaskParsing.cpp:376

Scope (from outer to inner):

file
function     void UE::Interchange::FTaskParsing::DoTask

Source code excerpt:

	CompletionPrerequistes.Append(GroupPrerequistes);

	if (!RenameAssets.IsEmpty())
	{
		TMap<TWeakObjectPtr<UInterchangeTranslatorBase>, FString> TranslatorMessageMap;
		for (const TPair<FString, FTaskParsingRenameInfo>& RenameAssetKvp : RenameAssets)
		{
			const FTaskParsingRenameInfo& RenameInfo = RenameAssetKvp.Value;
			FString& Message = TranslatorMessageMap.FindOrAdd(AsyncHelper->Translators[RenameInfo.SourceIndex]);
			Message += FText::Format(NSLOCTEXT("InterchangeTaskParsingDoTask", "RenamedAssetMessagePerAsset", "\n OriginalName:[{0}] NewName:[{1}]")
				, FText::FromString(RenameInfo.OriginalName)
				, FText::FromString(RenameInfo.NewName)).ToString();