The default setup of the AssetManager does not function in packaged builds: the Map asset type functions in PIE but not in a packaged build.
Repro:
- Create a new project (suggested: FirstPersonBP)
- If necessary, edit the “Maps” Primary Asset Type in the Asset Manager of the project settings to point at a directory with maps in it (for example, Game/FirstPersonBP/Maps for the FirstPersonBP template)
- On some sort of event which will fire (for example, on the shoot event in the FirstPersonBP character) add a GetPrimaryAssetIDList blueprint node, and log the size of the array it outputs to see how many maps it’s able to find.
- Run the game in PIE. Activate the event. Verify that the log reports that there is one map. (Or however many maps were in the folder your specified.)
- Package the game and run it. Activate the event. Observe that the number of maps will always be reported as zero, indicating that the AssetManager is unable to locate any maps.
I haven’t been able to fully figure out why this is happening, but it appears that the problem is probably related to the difference between UWorld and ULevel objects.
For the asset manager to be able to use an asset type as a Primary Asset in a packaged build, the asset’s type has to implement a GetPrimaryAssetID function. For some reason this isn’t the case when running in editor. (This is probably bad as it leads to nasty surprises when you package a build.) By default, the AssetManager is set up to locate all UWorld assets in the specified folder (Game/Maps by default). UWorld was modified with the addition of the AssetManager to have a GetPrimaryAssetID member to make them work with the AssetManager.
The problem is that UWorlds aren’t assets. Maps are ULevel objects, which have a UWorld outer, but are not UWorlds themselves. As far as I’m aware, you’ll never create a UWorld asset in the editor, they’re created at runtime to house one or more ULevels.
It looks like there’s some code somewhere which causes the AssetManager to find maps in the maps folder despite the fact that it’s looking for UWorlds and the maps are ULevels. I’m not sure whether this was a specific exception for UWorlds, or if there are transient UWorlds created for the ULevels in editor, or what, but the magic stops as soon as running in a packaged build. (The packaged build failure to find any maps whatsoever is actually what I would expect to happen in all cases, since the AssetManager has been told to look for UWorlds and not ULevels, but whatever.)
To make matters worse, this isn’t an easily fixable problem even in code, since there doesn’t appear to be any way to reparent a ULevel to a new class. (If you were, for example, to create a new class which inherits from ULevel which implemented a GetPrimaryAssetID member.)
To get this to work, I think you’d currently have to add a UPrimaryDataAsset wrapper for ULevels in order to make them function. But basically all the work to make the AssetManager work out of the box for maps does nothing ATM outside of the editor, and furthermore since UPrimaryDataAsset is not a BlueprintType, it makes the AssetManager impossible to use at all in Blueprint-only projects.