Asset Manager questions and possible bug.

Hello to all those that will read this post. I have many questions regarding the new Asset Manager feature set and felt this would be the best place to seek help. I also believe I have found a bug so I’ll start off by discussing those findings. Since I’m still trying to rap my head around the proper way to implement the Asset Manager I thought I would start off simple. I have been trying to follow the instructions within the Runtime Asset Manager PDF. The document states the following.

“Game-Specific Configuration
It’s possible to use the manual method above to scan for Primary Assets, but if your game is
complicated enough to have multiple asset types you will want to use the
PrimaryAssetTypesToScan​ member of AssetManagerSettings​. This is editable from the
[/Script/Engine.AssetManagerSettings] section of DefaultGame.ini, or via the Asset Manager
Project Settings tab.”

Because of the info listed above I went to Edit>Project Settings>Game>Asset Manager and added a new Primary Asset Type. I named this Primary Asset Type textureTestAsset and gave it a Base Class of Texture2D. I imported a few .png images into the following directory Content\Textures. I also added that directory to the newly created Primary Asset Type by clicking on the three dots to the right of the directory textbox. This is where I believe the bug comes into play. The directory listed within the textbox is “Textures”. However all other Primary Asset Directory’s begin with /Game. If I try to play the level without added /Game to the directly path the editor will crash. This leads me to believe that the Asset Manager is not properly listing the directly path within the DefaultGame.ini. Here are examples the the DefaultGame.ini for both before and after added the new Primary Asset Type.



[/Script/EngineSettings.GeneralProjectSettings]
Description=A temple scene with content created for the 'Full HDR' feature level mobile renderer
ProjectID=F2C6A84245B12E34817652B37C4483F9
ProjectName=Sun Temple

[/Script/UnrealEd.ProjectPackagingSettings]
BuildConfiguration=PPBC_Development
StagingDirectory=(Path=)
FullRebuild=False
ForDistribution=False
IncludeDebugFiles=False
UsePakFile=True
bGenerateChunks=False
bBuildHttpChunkInstallData=False
HttpChunkInstallDataDirectory=(Path=)
HttpChunkInstallDataVersion=
IncludePrerequisites=True
IncludeCrashReporter=True
InternationalizationPreset=English
-CulturesToStage=en
+CulturesToStage=en
DefaultCulture=en
bCookAll=False
bCookMapsOnly=False
bCompressed=False
+MapsToCook=(FilePath="/Game/Maps/SunTemple")

[/Script/EngineSettings.GeneralProjectSettings]
Description=A temple scene with content created for the 'Full HDR' feature level mobile renderer
ProjectID=36341A1440E47FB9BBC622B2B6E160C4
ProjectName=Sun Temple

[/Script/UnrealEd.ProjectPackagingSettings]
BuildConfiguration=PPBC_Development
StagingDirectory=(Path=)
FullRebuild=False
ForDistribution=False
IncludeDebugFiles=False
UsePakFile=True
bGenerateChunks=False
bBuildHttpChunkInstallData=False
HttpChunkInstallDataDirectory=(Path=)
HttpChunkInstallDataVersion=
IncludePrerequisites=True
IncludeCrashReporter=True
InternationalizationPreset=English
-CulturesToStage=en
+CulturesToStage=en
DefaultCulture=en
bCookAll=False
bCookMapsOnly=False
bCompressed=False
+MapsToCook=(FilePath="/Game/Maps/SunTemple")

[/Script/Engine.AssetManagerSettings]
-PrimaryAssetTypesToScan=(PrimaryAssetType="Map",AssetBaseClass=/Script/Engine.World,bHasBlueprintClasses=False,bIsEditorOnly=True,Directories=((Path="/Game/Maps")))
-PrimaryAssetTypesToScan=(PrimaryAssetType="PrimaryAssetLabel",AssetBaseClass=/Script/Engine.PrimaryAssetLabel,bHasBlueprintClasses=False,bIsEditorOnly=True,Directories=((Path="/Game")))
-PrimaryAssetTypesToScan=(PrimaryAssetType="Map",AssetBaseClass=/Script/Engine.World,bHasBlueprintClasses=False,bIsEditorOnly=True,Directories=((Path="/Game/Maps")),SpecificAssets=,Rules=(Priority=-1,bApplyRecursively=True,ChunkId=-1,CookRule=Unknown))
-PrimaryAssetTypesToScan=(PrimaryAssetType="PrimaryAssetLabel",AssetBaseClass=/Script/Engine.PrimaryAssetLabel,bHasBlueprintClasses=False,bIsEditorOnly=True,Directories=((Path="/Game")),SpecificAssets=,Rules=(Priority=-1,bApplyRecursively=True,ChunkId=-1,CookRule=Unknown))
-PrimaryAssetTypesToScan=(PrimaryAssetType="textureTestAsset",AssetBaseClass=/Script/Engine.Texture2D,bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=(()),SpecificAssets=,Rules=(Priority=-1,bApplyRecursively=True,ChunkId=-1,CookRule=Unknown))
+PrimaryAssetTypesToScan=(PrimaryAssetType="Map",AssetBaseClass=/Script/Engine.World,bHasBlueprintClasses=False,bIsEditorOnly=True,Directories=((Path="/Game/Maps")),SpecificAssets=,Rules=(Priority=-1,bApplyRecursively=True,ChunkId=-1,CookRule=Unknown))
+PrimaryAssetTypesToScan=(PrimaryAssetType="PrimaryAssetLabel",AssetBaseClass=/Script/Engine.PrimaryAssetLabel,bHasBlueprintClasses=False,bIsEditorOnly=True,Directories=((Path="/Game")),SpecificAssets=,Rules=(Priority=-1,bApplyRecursively=True,ChunkId=-1,CookRule=Unknown))
+PrimaryAssetTypesToScan=(PrimaryAssetType="textureTestAsset",AssetBaseClass=/Script/Engine.Texture2D,bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="Textures")),SpecificAssets=,Rules=(Priority=-1,bApplyRecursively=True,ChunkId=-1,CookRule=Unknown))
bOnlyCookProductionAssets=False


The path must be corrected within the DefaultGame.ini file. Attempting to alter the path within the Asset Manager will only affect the line that begin with a + and will not adjust the directory path for the lines that begin with a -.

Now I’d like to address some general questions I have regarding the Asset Manager.

The Runtime Asset Manager PDF make no mention of the - lines within the DefaultGame.ini file. It instead has the following line

!PrimaryAssetTypesToScan=ClearArray

Does this line provide the same functionality as the negative lines? Should I replace the negative lines with the line above? I only ask this because the Runtime Asset Manager PDF make no mention of them. Though I suspect this is just a result of the document being a bit out of date.

My next question is probably a bit stupid but here goes any way. What is the proper syntax for initializing a UAssetManager.

If I try



UAssetManager AM = UAssetManager::Get();


I get an inaccsessable error.

If I try



UAssetManager& AM = UAssetManager::Get();
int32 objectsFound = AM->ScanPathForPrimaryAssets(PrimaryAssetType, TEXT("/Game/"), UWorld::StaticClass(), false);


I get the error expression must have a pointer type.

If I try



UAssetManager* AM = UAssetManager::Get();


I get the error “No suitable conversion from UAssetManager to UAssetManager* exists”.

So for the time being I’m using the following code.



UAssetManager* AM;
AM = GEngine->AssetManager;


This seems to work but is obviously not correct and probably a bit unstable. Sorry to waste your time on C++ syntax related questions but I’m having a really hard time figuring this out.

So from this point I decided to attempt scanning a path for primary assets but I’m not finding anything. Here is some of the code I tried.



UAssetManager* AM;
AM = GEngine->AssetManager;
FPrimaryAssetType PrimaryAssetType = FName(TEXT("Map"));
int32 objectsFound = AM->ScanPathForPrimaryAssets(PrimaryAssetType, TEXT("/Game/Maps"), UWorld::StaticClass(), false);
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::FromInt(objectsFound));


I wanted to keep things simple so I decided to scan for one of the default Primary Asset Types. However this resulted in 0 objects found.
I was hoping someone could educate me on when I’m doing wrong here. Thanks in advance for any help I might receive.

UAssetManager::Get( ) uses GEngine->AssetManager anyways:



UAssetManager& UAssetManager::Get()
{
	UAssetManager* Singleton = GEngine->AssetManager;

	if (Singleton)
	{
		return *Singleton;
	}
	else
	{
		UE_LOG(LogAssetManager, Fatal, TEXT("Cannot use AssetManager if no AssetManagerClassName is defined!"));
		return *NewObject<UAssetManager>(); // never calls this
	}
}


Furthermore, in regards to syntax, it’s something like:



UAssetManager &AssetManager = UAssetManager::Get( );

// UAssetManager is a reference, no need to use pointer -> notation
int32 ObjectsFound = AssetManager.ScanPathForPrimaryAssets(FPrimaryAssetType("DebugType"), TEXT("/Game/"), UWorld::StaticClass(), false);


Yea when I couldn’t figure out the syntax I took a look at the source and that’s where I got the idea to use GEngine->AssetManager. Thanks for showing me the proper syntax.