Searching ContentBrowser to find chosen UObject,when engine loading.

Hey guys!
I am trying to make a tool plugin.
There are two UClass whitch be writed in different module.The one is inherited from UDeveloperSettings,just Name it as UMySetting.
The another is just UObject,name it as UMyObject.

Now, I want that… when the engine load,it will search ContentBrowser and find all of UMyObject and register their FAssetData in UMySetting.

For it, I run this function in construct of UMySetting

void UMySettings::SearchAssetAndRegister()
{
	FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
	TArray<FAssetData> AssetData;
	const UClass* Class = UMyObject::StaticClass();
	AssetRegistryModule.Get().GetAssetsByClass(Class->GetFName(), AssetData);

	Testint=AssetData.Num();
	
}

it can find nothing of UMyObject.The Testint be 0.
If I search others class,such as ACharacter,it still can not find,but it can find StaticMesh. Why for that?
by the way,the LoadingPhase for module of UMyObject is set “PostConfigInit”.
and the module of UMySetting is set “PostEngineInit”. if the LoadingPhase will make some influence?

I have found the solution for this problem.

First,I study a lot,and decide to use EngineSubsystem to replace the InheritClass of UDeveloperSettings,EngineSubsystem is better as a manager.

and make function for searching ContentBrowser,just like this.

void UMyEngineSubsystem::SearchAssetAndRegister()
{
	FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
	TArray<FAssetData> AssetData;
	const UClass* Class = UMyObject::StaticClass();
	AssetRegistryModule.Get().GetAssetsByClass(Class->GetFName(), AssetData);

	Testint=AssetData.Num();
	
}

then, band a series of delegates from OnPostEngineInit to UAssetManager::CallOrRegister_OnCompletedInitialScan.
the searching function will be call after AssetManager Scan completed.

like this:

void UMyEngineSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
      FCoreDelegates::OnPostEngineInit.AddUObject(this, &UMyEngineSubsystem::PostEngineInit);
}
void UMyEngineSubsystem::PostEngineInit()
{
      UAssetManager* AssetManager = UAssetManager::GetIfValid();

      if (AssetManager)
     {
	AssetManager- >CallOrRegister_OnCompletedInitialScan(FSimpleMulticastDelegate::FDelegate::CreateUObject(this, &UMyEngineSubsystem::PostAssetManager));
      }
}
void UMyEngineSubsystem::PostAssetManager()
{
      SearchAssetAndRegister();
}

the code can refer to the official plugin “DataRegistry”

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.