You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
This change consists of multiple changes: Core: - Deprecation of ANY_PACKAGE macro. Added ANY_PACKAGE_DEPRECATED macro which can still be used for backwards compatibility purposes (only used in CoreUObject) - Deprecation of StaticFindObjectFast* functions that take bAnyPackage parameter - Added UStruct::GetStructPathName function that returns FTopLevelAssetPath representing the path name (package + object FName, super quick compared to UObject::GetPathName) + wrapper UClass::GetClassPathName to make it look better when used with UClasses - Added (Static)FindFirstObject* functions that find a first object given its Name (no Outer). These functions are used in places I consider valid to do global UObject (UClass) lookups like parsing command line parameters / checking for unique object names - Added static UClass::TryFindType function which serves a similar purpose as FindFirstObject however it's going to throw a warning (with a callstack / maybe ensure in the future?) if short class name is provided. This function is used in places that used to use short class names but now should have been converted to use path names to catch any potential regressions and or edge cases I missed. - Added static UClass::TryConvertShortNameToPathName utility function - Added static UClass::TryFixShortClassNameExportPath utility function - Object text export paths will now also include class path (Texture2D'/Game/Textures/Grass.Grass' -> /Script/Engine.Texture2D'/Game/Textures/Grass.Grass') - All places that manually generated object export paths for objects will now use FObjectPropertyBase::GetExportPath - Added a new startup test that checks for short type names in UClass/FProperty MetaData values AssetRegistry: - Deprecated any member variables (FAssetData / FARFilter) or functions that use FNames to represent class names and replaced them with FTopLevelAssetPath - Added new member variables and new function overloads that use FTopLevelAssetPath to represent class names - This also applies to a few other modules' APIs to match AssetRegistry changes Everything else: - Updated code that used ANY_PACKAGE (depending on the use case) to use FindObject(nullptr, PathToObject), UClass::TryFindType (used when path name is expected, warns if it's a short name) or FindFirstObject (usually for finding types based on user input but there's been a few legitimate use cases not related to user input) - Updated code that used AssetRegistry API to use FTopLevelAssetPaths and USomeClass::StaticClass()->GetClassPathName() instead of GetFName() - Updated meta data and hardcoded FindObject(ANY_PACKAGE, "EEnumNameOrClassName") calls to use path names #jira UE-99463 #rb many.people [FYI] Marcus.Wassmer #preflight 629248ec2256738f75de9b32 #codereviewnumbers 20320742, 20320791, 20320799, 20320756, 20320809, 20320830, 20320840, 20320846, 20320851, 20320863, 20320780, 20320765, 20320876, 20320786 #ROBOMERGE-OWNER: robert.manuszewski #ROBOMERGE-AUTHOR: robert.manuszewski #ROBOMERGE-SOURCE: CL 20430220 via CL 20433854 via CL 20435474 via CL 20435484 #ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v949-20362246) [CL 20448496 by robert manuszewski in ue5-main branch]
162 lines
6.4 KiB
C++
162 lines
6.4 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "Commandlets/SwapSoundForDialogueInCuesCommandlet.h"
|
|
#include "Modules/ModuleManager.h"
|
|
#include "SoundCueGraph/SoundCueGraph.h"
|
|
#include "SoundCueGraph/SoundCueGraphNode.h"
|
|
#include "AssetRegistry/AssetData.h"
|
|
#include "Sound/SoundWave.h"
|
|
#include "Sound/DialogueWave.h"
|
|
#include "Sound/SoundCue.h"
|
|
#include "AssetRegistry/ARFilter.h"
|
|
#include "AssetRegistry/AssetRegistryModule.h"
|
|
#include "Sound/SoundNodeDialoguePlayer.h"
|
|
#include "Sound/SoundNodeWavePlayer.h"
|
|
#include "AudioEditorModule.h"
|
|
#include "LocalizedAssetUtil.h"
|
|
#include "LocalizationSourceControlUtil.h"
|
|
|
|
DEFINE_LOG_CATEGORY_STATIC(LogSwapSoundForDialogueInCuesCommandlet, Log, All);
|
|
|
|
int32 USwapSoundForDialogueInCuesCommandlet::Main(const FString& Params)
|
|
{
|
|
// Prepare asset registry.
|
|
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));
|
|
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get();
|
|
AssetRegistry.SearchAllAssets(true);
|
|
|
|
// Parse command line.
|
|
TArray<FString> Tokens;
|
|
TArray<FString> Switches;
|
|
TMap<FString, FString> Parameters;
|
|
UCommandlet::ParseCommandLine(*Params, Tokens, Switches, Parameters);
|
|
|
|
TSharedPtr<FLocalizationSCC> SourceControlInfo;
|
|
const bool bEnableSourceControl = Switches.Contains(TEXT("EnableSCC"));
|
|
if (bEnableSourceControl)
|
|
{
|
|
SourceControlInfo = MakeShareable(new FLocalizationSCC());
|
|
|
|
FText SCCErrorStr;
|
|
if (!SourceControlInfo->IsReady(SCCErrorStr))
|
|
{
|
|
UE_LOG(LogSwapSoundForDialogueInCuesCommandlet, Error, TEXT("Source Control error: %s"), *SCCErrorStr.ToString());
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
// We only want dialogue wave assets that exist within the Game content directory.
|
|
TArray<FAssetData> AssetDataArrayForDialogueWaves;
|
|
if (!FLocalizedAssetUtil::GetAssetsByPathAndClass(AssetRegistry, FName("/Game"), UDialogueWave::StaticClass()->GetClassPathName(), /*bIncludeLocalizedAssets*/false, AssetDataArrayForDialogueWaves))
|
|
{
|
|
UE_LOG(LogSwapSoundForDialogueInCuesCommandlet, Error, TEXT("Unable to get dialogue wave asset data from asset registry."));
|
|
return -1;
|
|
}
|
|
|
|
for (const FAssetData& AssetData : AssetDataArrayForDialogueWaves)
|
|
{
|
|
// Verify that the found asset is a dialogue wave.
|
|
if (AssetData.GetClass() != UDialogueWave::StaticClass())
|
|
{
|
|
UE_LOG(LogSwapSoundForDialogueInCuesCommandlet, Error, TEXT("Asset registry found asset (%s), but the asset with this name is not actually a dialogue wave."), *AssetData.AssetName.ToString());
|
|
continue;
|
|
}
|
|
|
|
// Get the dialogue wave.
|
|
UDialogueWave* const DialogueWave = Cast<UDialogueWave>(AssetData.GetAsset());
|
|
|
|
// Verify that the dialogue wave was loaded.
|
|
if (!DialogueWave)
|
|
{
|
|
UE_LOG(LogSwapSoundForDialogueInCuesCommandlet, Error, TEXT("Asset registry found asset (%s), but the dialogue wave could not be accessed."), *AssetData.AssetName.ToString());
|
|
continue;
|
|
}
|
|
|
|
// Iterate over each of the contexts and fix up the sound cue nodes referencing this sound wave.
|
|
for (const FDialogueContextMapping& ContextMapping : DialogueWave->ContextMappings)
|
|
{
|
|
// Skip contexts without sound waves.
|
|
const USoundWave* const SoundWave = ContextMapping.SoundWave;
|
|
if (!SoundWave)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Verify that the sound wave has a package.
|
|
const UPackage* const SoundWavePackage = SoundWave->GetOutermost();
|
|
if (!SoundWavePackage)
|
|
{
|
|
UE_LOG(LogSwapSoundForDialogueInCuesCommandlet, Error, TEXT("Asset registry found dialogue wave (%s) with a context referencing sound wave (%s) but no package exists for this sound wave."), *AssetData.AssetName.ToString(), *SoundWave->GetName());
|
|
continue;
|
|
}
|
|
|
|
// Find referencers of the context's sound wave.
|
|
TArray<FName> SoundWaveReferencerNames;
|
|
if (!AssetRegistry.GetReferencers(SoundWavePackage->GetFName(), SoundWaveReferencerNames))
|
|
{
|
|
UE_LOG(LogSwapSoundForDialogueInCuesCommandlet, Error, TEXT("Asset registry found dialogue wave (%s) with a context referencing sound wave (%s) but failed to search for referencers of the sound wave."), *AssetData.AssetName.ToString(), *SoundWave->GetName());
|
|
continue;
|
|
}
|
|
|
|
// Skip further searching if there are no sound wave referencers.
|
|
if (SoundWaveReferencerNames.Num() == 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Get sound cue assets that reference the context's sound wave.
|
|
FARFilter Filter;
|
|
Filter.ClassPaths.Add(USoundCue::StaticClass()->GetClassPathName());
|
|
Filter.bRecursiveClasses = true;
|
|
Filter.PackageNames = SoundWaveReferencerNames;
|
|
TArray<FAssetData> ReferencingSoundCueAssetDataArray;
|
|
if (!AssetRegistry.GetAssets(Filter, ReferencingSoundCueAssetDataArray))
|
|
{
|
|
UE_LOG(LogSwapSoundForDialogueInCuesCommandlet, Error, TEXT("Asset registry found dialogue wave (%s) with a context referencing sound wave (%s) but failed to search for sound cues referencing the sound wave."), *AssetData.AssetName.ToString(), *SoundWave->GetName());
|
|
continue;
|
|
}
|
|
|
|
// Iterate through referencing sound cues, finding sound node wave players and replacing them
|
|
for (const FAssetData& SoundCueAssetData : ReferencingSoundCueAssetDataArray)
|
|
{
|
|
USoundCue* const SoundCue = Cast<USoundCue>(SoundCueAssetData.GetAsset());
|
|
|
|
// Verify that the sound cue exists.
|
|
if (!SoundCue)
|
|
{
|
|
UE_LOG(LogSwapSoundForDialogueInCuesCommandlet, Error, TEXT("Asset registry found dialogue wave (%s) with a context referencing sound wave (%s) but failed to access the referencing sound cue (%s)."), *AssetData.AssetName.ToString(), *SoundWave->GetName(), *SoundCueAssetData.AssetName.ToString());
|
|
continue;
|
|
}
|
|
|
|
// Iterate through sound nodes in this sound cue and find those that need replacing.
|
|
TArray<USoundNode*> NodesToReplace;
|
|
for (USoundNode* const SoundNode : SoundCue->AllNodes)
|
|
{
|
|
USoundNodeWavePlayer* const SoundNodeWavePlayer = Cast<USoundNodeWavePlayer>(SoundNode);
|
|
|
|
// Skip nodes that are not sound wave players or not referencing the sound wave in question.
|
|
if (SoundNodeWavePlayer && SoundNodeWavePlayer->GetSoundWave() == SoundWave)
|
|
{
|
|
NodesToReplace.Add(SoundNode);
|
|
}
|
|
}
|
|
if (NodesToReplace.Num() == 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
IAudioEditorModule* AudioEditorModule = &FModuleManager::LoadModuleChecked<IAudioEditorModule>("AudioEditor");
|
|
AudioEditorModule->ReplaceSoundNodesInGraph(SoundCue, DialogueWave, NodesToReplace, ContextMapping);
|
|
|
|
// Execute save.
|
|
if (!FLocalizedAssetSCCUtil::SaveAssetWithSCC(SourceControlInfo, SoundCue))
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|