HI @MagForceSeven
Thanks for your previous reply. I understand that the AssetManager and AssetRegistry work fine in non-editor builds.
I’ve been testing further in the editor, and I’m still seeing issues on the first play after compiling or restarting the editor. Some assets don’t seem to get registered/scanned properly, even with only a few files.
The Assets Manager scan always fails on the first play after compiling or restarting the editor. It works fine from the second play onwards.
Forcing registration doesn’t fix it. Not all assets in the folders are properly registered/scanned, even with only 10 files.
Tested in UE5.6 and UE5.6.1 in the editor. Haven’t tried a cooked version yet. This behavior raises concerns about the system’s reliability. If this isn’t a bug, I’d like to know the cause and if there’s a way to prevent it.
This code is a summary of what I’m doing. On the first play, the list printed in PrintIDList() doesn’t show all the assets from the folders. The RegistryFailback() function fails on all attempts to register the missing assets. And in the LoadNextAsset() function, I get an invalid handle.
However, on subsequent plays everything works perfectly. So it’s all very puzzling.
//-----------------------------------------------------------------------------------------------------
void UClientAssetsLoaderSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
check(UAssetManager::IsInitialized());
UAssetManager& Manager = UAssetManager::Get();
Manager.CallOrRegister_OnCompletedInitialScan(
FSimpleMulticastDelegate::FDelegate::CreateUObject
(
this, &UClientAssetsLoaderSubsystem::OnAssetManagerInitialScanComplete
));
}
//-----------------------------------------------------------------------------------------------------
void UClientAssetsLoaderSubsystem::OnAssetManagerInitialScanComplete()
{
PrintIDList();
DiscoverAssetsAsync();
}
//-----------------------------------------------------------------------------------------------------
void UClientAssetsLoaderSubsystem::PrintIDList()
{
UAssetManager& Manager = UAssetManager::Get();
TArray<FPrimaryAssetId> IdList;
Manager.GetPrimaryAssetIdList(UClientMasterAsset::GetType(), IdList, EAssetManagerFilter::Default);
for (FPrimaryAssetId &ID : IdList)
{
UE_LOG(LogTemp, Log, TEXT("UClientAssetsLoaderSubsystem::PrintIDList --> Asset ID = %s"), *ID.ToString());
}
}
//-----------------------------------------------------------------------------------------------------
bool UClientAssetsLoaderSubsystem::RegistryFailback(const FSoftObjectPath& Path, const FPrimaryAssetId &AssetId)
{
FAssetData AssetData;UAssetManager& Manager = UAssetManager::Get();
if(!Manager.GetAssetDataForPath(Path, AssetData))
{
IAssetRegistry& Registry = FModuleManager::LoadModuleChecked<FAssetRegistryModule> ("AssetRegistry").Get();
AssetData = Registry.GetAssetByObjectPath(Path, true);
if (!AssetData.IsValid())
{
UE_LOG(LogTemp, Error, TEXT("UClientAssetsLoaderSubsystem::RegistryFailback --> AssetData is not valid for path: %s"), *Path.ToString());
return false;
}
}
if (!Manager.RegisterSpecificPrimaryAsset(AssetId, AssetData))
{
UE_LOG(LogTemp, Error, TEXT("UClientAssetsLoaderSubsystem::RegistryFailback --> Registration failed for AssetId: %s"), *AssetId.ToString());
return false;
}
return true;
}
//-----------------------------------------------------------------------------------------------------
void UClientAssetsLoaderSubsystem::LoadNextAsset()
{
if (!RegistryFailback(AssetList[CurrentAssetIndex].AssetPath, AssetList[CurrentAssetIndex].AssetId))
{
UE_LOG(LogTemp, Error, TEXT(“UClientAssetsLoaderSubsystem::LoadNextAsset → Asset is not registered: %s”), *AssetList[CurrentAssetIndex].AssetId.ToString());
return;
}
TArray<FName> Bundles;
Bundles.Add(FName("Default"));
const FStreamableDelegate &Delegate = FStreamableDelegate::CreateUObject(this, &UClientAssetsLoaderSubsystem::HandleLoadCompleted);
UAssetManager& Manager = UAssetManager::Get()
Handle = Manager.LoadPrimaryAsset(AssetList[CurrentAssetIndex].AssetId, Bundles, Delegate, FStreamableManager::AsyncLoadHighPriority);
}
//-----------------------------------------------------------------------------------------------------
I’d really appreciate any guidance on what might cause this or how to ensure all assets are registered correctly on first play.
Thanks again,
Iván