AssetManager.LoadPrimaryAsset not working... what am I doing wrong?

Hi,

after delving on the official documentation, studying Ben Zeigler livestream (Asset Manager Explained | Inside Unreal - YouTube) and checking the Action RPG project, I tried to use the Asset Manager on my own, but without success… and I can’t get what I’m doing wrong.

To start with: my understanding is that you define “Primary Assets” so that you can control their “chunking” and also so that you can control when these assets gets loaded and unloaded. In this process, any asset referenced by a Primary Asset (“Secondary Asset”) gets also loaded and unloaded together with the Primary Asset it belongs to.

What I would like to do is to (i) load a set Actors at a given moment (ii) keep these assets loaded in memory (iii) assign the packaging of these Assets to a given chunk. For the sake of simplicity, let’s keep chunking aside for the moment and let’s say I want to load these Actors as the game is launched.

To that end, I have
1. Derived a class from UPrimaryDataAsset, where I reference the three assets I want to (pre)load:

UCLASS()
class LOADTESTER_API UMyPrimaryDataAsset : public UPrimaryDataAsset
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, AssetRegistrySearchable, meta = (AssetBundles = "Game"))
	TSubclassOf<AActor> CharacterOne;

	UPROPERTY(EditAnywhere, AssetRegistrySearchable, meta = (AssetBundles = "Game"))
	TSubclassOf<AActor> CharacterTwo;

	UPROPERTY(EditAnywhere, AssetRegistrySearchable, meta = (AssetBundles = "Game"))
	TSubclassOf<AActor> CharacterThree;

};

Note: I’ve tried to reference my Assets also with TAssetSubClassOf (vs TSubClassOf) to no avail

2. Derived a Blueprint out of MyPrimaryDataAsset, where I assigned the corresponding UProperties to the three actors I want to load. I called the Blueprint BP_PrimAsset

3. Set up Project Settings|Asset Manager to recognize my Primary Asset as such:
image

4. Try to load the Primary Asset in my GameInstance::Init(), as such:

void ULoadTesterGameInstance::Init()
{
	Super::Init();

	UAssetManager& AssetManager = UAssetManager::Get();
	TArray<FPrimaryAssetId> MyPrimaryAssetIdArray;

	TArray<FName> CurrentLoadState;
	CurrentLoadState.Add(FName("Game"));

	FPrimaryAssetId myPrimaryAssetToLoad = FPrimaryAssetId(FName("PrimAsset"), FName("BP_PrimAsset"));

	AssetManager.LoadPrimaryAsset(myPrimaryAssetToLoad, CurrentLoadState, FStreamableDelegate::CreateUObject(this, &ULoadTesterGameInstance::CallbackFunction, myPrimaryAssetToLoad));
}

void ULoadTesterGameInstance::CallbackFunction(FPrimaryAssetId id)
{
	GEngine->AddOnScreenDebugMessage(1, 5, FColor::Yellow, FString("DONE"));
	UE_LOG(LogTemp, Warning, TEXT("Loading happened"));
}

5. Aaaaand these are the results:

  • The CallBack function gets called immediately, both in Editor and in the Packaged Game. This makes no sense, as I made sure to reference asset for a total of 5 Gigabyte, that take at least a couple seconds to load.

  • In Editor, the Assets are actually loaded. I know this by launching the console command “obj list”

  • In Play in Editor or Play As Standalone Game or in the Packaged Game the Asset do not get loaded …but when they are actually needed (my whole point is to have them already loaded by the time the game needs them).

My question, as per title of this post: what am I doing wrong? What’s the correct way to use the AssetManager to actually load and unload (primary) assets at will?

A big Thank You in advance to whomever can help!

Cheers,
f

Bumping this. If anybody just know how to point me to the right direction – a tutorial, a video or an article explaining this from the basics (Zeigler’s video gives a lot for granted) – that’d be enough!

Thanks

f

Hey there,

Look at this Asset Manager for Data Assets & Async Loading - Tom Looman. It will answer your question.

1 Like