Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright Luzera Studio. All Rights Reserved.
- #include "LuzeraBenchmarkTool.h"
- #include "AssetRegistry/AssetRegistryModule.h"
- #include "Engine/AssetManagerSettings.h"
- #include "Subsystems/BenchmarkSessionSubsystem.h"
- #define LOCTEXT_NAMESPACE "FLuzeraBenchmarkToolModule"
- /**
- * @brief Called when the module is loaded into memory.
- */
- void FLuzeraBenchmarkToolModule::StartupModule()
- {
- // --- Find and Register the user's Benchmark Subsystem Blueprint ---
- UAssetManagerSettings* Settings = GetMutableDefault<UAssetManagerSettings>();
- if (!Settings) return;
- // 1. Find the user's Blueprint asset that inherits from our C++ base class.
- const FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));
- TArray<FAssetData> SubsystemAssets;
- FARFilter Filter;
- Filter.ClassPaths.Add(UBlueprint::StaticClass()->GetClassPathName());
- // We filter for Blueprints whose C++ parent is our abstract subsystem class.
- Filter.TagsAndValues.Add(FBlueprintTags::NativeParentClassPath, FObjectPropertyBase::GetExportPath(UBenchmarkSessionSubsystem::StaticClass()));
- AssetRegistryModule.Get().GetAssets(Filter, SubsystemAssets);
- if (SubsystemAssets.Num() == 0)
- {
- UE_LOG(LogTemp, Warning, TEXT("LuzeraBenchmarkTool: No Blueprint based on UBenchmarkSessionSubsystem found. It will not be available in packaged builds until one is created."));
- return;
- }
- // 2. Load the Blueprint asset and get its generated class.
- UBlueprint* BlueprintAsset = Cast<UBlueprint>(SubsystemAssets[0].GetAsset());
- if (!BlueprintAsset || !BlueprintAsset->GeneratedClass)
- {
- UE_LOG(LogTemp, Error, TEXT("LuzeraBenchmarkTool: Found a subsystem Blueprint, but it failed to load or has no generated class."));
- return;
- }
- UClass* BlueprintClass = BlueprintAsset->GeneratedClass;
- // 3. The Primary Asset Type will be the name of the Blueprint class (e.g., BP_Benchmark_Subsystem_C).
- const FName BlueprintAssetType = BlueprintClass->GetFName();
- // 4. Check if this specific Blueprint is already registered.
- bool bIsAlreadyRegistered = false;
- for (const FPrimaryAssetTypeInfo& AssetTypeInfo : Settings->PrimaryAssetTypesToScan)
- {
- if (AssetTypeInfo.PrimaryAssetType == BlueprintAssetType)
- {
- bIsAlreadyRegistered = true;
- break;
- }
- }
- // 5. If it's not registered, add it now.
- if (!bIsAlreadyRegistered)
- {
- // The AssetBaseClass is now the specific Blueprint class found above.
- FPrimaryAssetTypeInfo NewAssetTypeInfo(
- BlueprintAssetType,
- BlueprintClass, // Use the actual Blueprint class here
- true, // It has Blueprint classes
- false
- );
- NewAssetTypeInfo.Rules.CookRule = EPrimaryAssetCookRule::AlwaysCook;
- Settings->PrimaryAssetTypesToScan.Add(NewAssetTypeInfo);
- Settings->SaveConfig();
- UE_LOG(LogTemp, Log, TEXT("LuzeraBenchmarkTool: Automatically registered '%s' with the Asset Manager."), *BlueprintAssetType.ToString());
- }
- }
- /**
- * @brief Called before the module is unloaded from memory.
- */
- void FLuzeraBenchmarkToolModule::ShutdownModule()
- {
- // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
- // we call this function before unloading the module.
- }
- #undef LOCTEXT_NAMESPACE
- IMPLEMENT_MODULE(FLuzeraBenchmarkToolModule, LuzeraBenchmarkTool)
Advertisement
Add Comment
Please, Sign In to add comment