Registering and Loading Primary Assets From Disk
Most Primary Assets can be found in the Content Browser and exist as Asset files stored on disk, so that they can be edited by artists or designers. The easiest way for a programmer to create a class that can be used in this way is to inherit from
UPrimaryDataAsset, which is a version of
UDataAsset that has the functionality for loading and saving Asset Bundle data built in. If a different base class is desired, such as
UPrimaryDataAsset is useful as a minimal example of the features that must be added to get Asset Bundles working for your class. The following class stores Zone Theme data in Fortnite, which tells the game what art Assets to use when building the visual representation of an area in the game's map selection mode:
/** A zone that can be selected by the user from the map screen */
class FORTNITEGAME_API UFortZoneTheme : public UPrimaryDataAsset
/** Name of the zone */
/** The map that will be loaded when entering this zone */
/** The blueprint class used to represent this zone on the map */
UPROPERTY(EditDefaultsOnly, Category=Visual, meta=(AssetBundles = "Menu"))
TAssetSubclassOf<class AFortTheaterMapTile> TheaterMapTileClass;
Because this class inherits from
UPrimaryDataAsset, it has a working version of
GetPrimaryAssetId that uses the Asset’s short name and native class. For example, a
UFortZoneTheme saved under the name "Forest" would have a Primary Asset ID of "FortZoneTheme:Forest". Whenever a
UFortZoneTheme Asset is saved in the Editor, the
AssetBundleData member of
PrimaryDataAsset will be updated to include it as a Secondary Asset.
Registering and loading our Primary Assets requires the following actions:
The default Asset Manager class does not need to be overridden unless there is a need for special functionality. The default Engine class,
UAssetManager, can be used, in which case this step can be skipped.
Register your Primary Assets with the Asset Manager. This can be done in three ways: by configuring with the Project Settings menu, by manually adding an array of Asset paths to scan in
DefaultGame.ini, or by programming your Asset Manager class to do so during startup.
Paths to scan for primary Assets can be configured.
Primary Asset Types to Scan
Lists the types of Primary Assets to discover and register, as well as where to look for them and what to do with them.
Directories to Exclude
Directories that will explicitly not be scanned for Primary Assets. This is useful for excluding test Assets.
Primary Asset Rules
Lists the specific Rules Overrides, which dictate how Assets are handled. See Cooking and Chunking for more information.
Only Cook Production Assets
Assets designated as DevelopmentCook will cause errors during the cook process if this is checked. Good for ensuring that final, shipping builds are free of test Assets.
Primary Asset ID Redirects
When the Asset Manager looks up data about a Primary Asset whose ID appears in this list, the ID will be substituted for the alternate ID provided.
Primary Asset Type Redirects
When the Asset Manager looks up data about a Primary Asset, the type name provided in this list will be used instead of its native type.
Primary Asset Name Redirects
When the Asset Manager looks up data about a Primary Asset, the Asset name provided in this list will be used instead of its native name.
DefaultGame.ini, find (or create) a section called
/Script/Engine.AssetManagerSettings and add your Primary Asset classes manually. The format looks like this:
If you want to register Primary Assets directly in code, override the
StartInitialLoading function in your Asset Manager class and call
ScanPathsForPrimaryAssets from there. In this case, it is recommended that you put all Primary Assets of the same type in the same subfolder. This will make Asset discovery and registration faster.
Load the Asset. The Asset Manager functions
LoadPrimaryAssetsWithType can be used to begin loading Primary Assets at the appropriate time. Assets can be unloaded later with
UnloadPrimaryAssetsWithType. When using these load functions, a list of Asset Bundles can be specified. Loading this way will cause the Asset Manager to load the Secondary Assets referenced by those Asset Bundles as described above.