What is Asset Registry used for?

What is the difference between “LoadObject, FindObject” and “Asset Registry”?

My english is not very well and I have difficulty to understand AssetRegistry.

Could you give an example in C++? In which situations do we need to use it?

To understand what asset registry is you need to understand what asset is in technical term.

Asset is a UObject that can be dumped down to file (uasset package) and can be loaded back to the memory from that file and in is mainly used to store game resources, when you load them they are avable in memory as UObject objects like UBlueprint, UTexture2D, USkeletalMesh. USoundWave and so on. Every type of asset you see in content browser has corresponding class and each asset you see in “content Browser” is a UObject that is in memory or can be loaded in memory.

As assets are UObjects normally you would seek them out from reflection system. But because assets exists also on files and don’t need to be loaded to memory all the time when they are unused (they would just waste memory space), there need to be object that needs to keep track of them regardless if they are loaded or not. Searching them in reflection system is pointless if they are not loaded first. And that what AsssetRegistry is. it allows you to list out assets, get there regestry entry (FAssetData) and load them up, it also a to more optimized way to seek assets that are loaded already, as well as edit there registry information. And yes “Content Browser” in reality is Asset Registry explorer and it mainly use AssetRegistry to list and edit assets in there. It also provides event delegates which let you track live any changes done to asset registry.

Best way to just look in API refrence to see what function it gives:

https://api.unrealengine.com/INT/API/Runtime/AssetRegistry/IAssetRegistry/index.html

You can always access from anywhere via:

AssetRegistryModule.Get()->...

Assets in registry are stored in paths (which you see as folder structure in content browser), if you want to request specific asset you need to know path for it (you can get it by right clicking asset and clicking Copy Reference). but you can also whole sets of assets using diffrent identificators. for example you can get all assets of specific class (class name as name if the asset class without U prefix:

https://api.unrealengine.com/INT/API/Runtime/AssetRegistry/IAssetRegistry/GetAssetsByClass/index.html

TArray<FAssetData> Assets;
AssetRegistryModule.Get()->GetAssetsByClass(FName("Texture2D"),Assets,true);

And oyu will get registry entires of assets in form of array of FAssetData structures:

https://api.unrealengine.com/INT/API/Runtime/AssetRegistry/FAssetData/index.html

And you can load and get asset UObject it self by calling GetAsset()

LoadObject is a function that loads UObject form the file, it function is useful if you want to load asset (or not) that is outside of asset registry.

Find Object on other hand finds assets that is already loaded in memory.

3 Likes

Thanks. It is very helpful.

But I don’t understand this “LoadObject is a function that loads UObject form the file, it function is useful if you want to load asset (or not) that is outside of asset registry.

Asset Registery: list out assets, load assets, assets informations, load asset with path
Load Object: just load assets with path

Is this the only difference? If I only load asset with path, do I need it?

Here are the updated links of the documentation

https://docs.unrealengine.com/4.27/en-US/API/Runtime/AssetRegistry/AssetRegistry/FAssetRegistryModule/

https://docs.unrealengine.com/4.26/en-US/API/Runtime/AssetRegistry/IAssetRegistry/GetAssetByObjectPath/

https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/Assets/Registry/

1 Like

For anyone looking to load a single asset from the registry

FName DataAssetLocation = (TEXT("/Game/MyDataAsset.MyDataAsset"));

FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
FAssetData AssetData = AssetRegistryModule.Get().GetAssetByObjectPath(DataAssetLocation);

if (AssetData.IsValid())
{
	UMyDataAsset* Data = Cast<UMyDataAsset> (AssetData.GetAsset());
	UE_LOG(LogTemp, Warning, TEXT("*** File Found ***"));	
}
else
{
	UE_LOG(LogTemp, Warning, TEXT("***  Failed ***"));
}
1 Like