Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::Data::Asset< T > Class Template Reference

#include <AssetCommon.h>

Public Member Functions

 Asset (AssetLoadBehavior loadBehavior=AssetLoadBehavior::Default)
 
 Asset (AssetData *assetData, AssetLoadBehavior loadBehavior)
 Create an asset from a valid asset data (created asset), might not be loaded or currently loading.
 
 Asset (const AZ::Data::AssetId &id, AssetData *assetData, AssetLoadBehavior loadBehavior)
 Create an asset from a valid asset data (created asset) and set the asset id for both, might not be loaded or currently loading.
 
 Asset (const AZ::Data::AssetId &id, const AZ::Data::AssetType &type, const AZStd::string &hint=AZStd::string())
 Initialize asset pointer with id, type, and hint. No data construction will occur until QueueLoad is called.
 
 Asset (const Asset &rhs)
 
template<typename U >
 Asset (const Asset< U > &rhs)
 
 Asset (Asset &&rhs)
 
Assetoperator= (Asset &&rhs)
 
Assetoperator= (const Asset &rhs)
 
 operator bool () const
 
T & operator* () const
 
T * operator-> () const
 
bool IsReady () const
 Is the asset data ready (loaded)?
 
bool IsError () const
 Did an error occur when loading the asset?
 
bool IsLoading () const
 Is the asset currently loading?
 
AssetData::AssetStatus GetStatus () const
 What is the current load status of the asset?
 
const AssetIdGetId () const
 Retrieve the Id of the referenced asset.
 
const AssetTypeGetType () const
 Retrieve the type of the referenced asset (if available).
 
const AZStd::stringGetHint () const
 Retrieve the last known path to the asset Id this ref is bound to.
 
void SetHint (const AZStd::string &newHint)
 
AssetDataGetData () const
 Returns asset data - base class.
 
T * Get () const
 Returns pointer to the asset type, or null if asset is not loaded.
 
template<class U >
U * GetAs () const
 Return asset data as T type, uses azrtti for the cast.
 
bool Create (const AssetId &id, bool queueLoad=false)
 
bool Create (const AssetId &id, AssetLoadBehavior loadBehavior, bool queueLoad=false)
 
bool QueueLoad (const AssetLoadParameters &loadParams={})
 
AssetData::AssetStatus BlockUntilLoadComplete ()
 
bool Reset ()
 
bool Release ()
 
bool Reload ()
 
bool Save ()
 
void SetAutoLoadBehavior (AssetLoadBehavior loadBehavior)
 
AssetLoadBehavior GetAutoLoadBehavior () const
 
u8 GetFlags () const
 
bool SetFlags (u8 flags)
 
void UpgradeAssetInfo ()
 
template<class StringType >
StringType ToString () const
 
template<class StringType >
void ToString (StringType &result) const
 

Protected Member Functions

void SetData (AssetData *assetData)
 
void swap (Asset &rhs)
 

Protected Attributes

AssetId m_assetId
 Id of asset the pointer currently references. QueueLoad will acquire/load the actual asset.
 
AssetType m_assetType
 Referenced asset type.
 
AssetDatam_assetData = nullptr
 Pointer to the asset data, it's always present when we have bound an asset (it doesn't have to be loaded)
 
AssetLoadBehavior m_loadBehavior
 Load behavior for the asset reference.
 
AZStd::string m_assetHint
 Last known path to the asset m_assetId refers to.
 

Friends

class AssetManager
 
class AZ::AssetSerializer
 
class AZ::AssetEventHandler
 

Detailed Description

template<class T>
class AZ::Data::Asset< T >

Asset is a smart pointer to an actual asset. Asset users should always refer to assets using this object.

Constructor & Destructor Documentation

◆ Asset()

template<class T >
AZ::Data::Asset< T >::Asset ( AssetLoadBehavior  loadBehavior = AssetLoadBehavior::Default)

Create asset with default params (no asset bounded) By default, referenced assets will be queued for load during serialization. Use AssetLoadBehavior to control this behavior.

Asset<T>

Member Function Documentation

◆ Create() [1/2]

template<class T >
bool AZ::Data::Asset< T >::Create ( const AssetId id,
AssetLoadBehavior  loadBehavior,
bool  queueLoad = false 
)

Create an asset with an ID and loadBehavior (type is inferred). If there is a current asset it will be released.

Parameters
idAssetId
loadBehaviorAssetLoadBehavior
queueLoadif true it will call "QueueLoad" to load the asset data.

◆ Create() [2/2]

template<class T >
bool AZ::Data::Asset< T >::Create ( const AssetId id,
bool  queueLoad = false 
)

Create an asset with an ID (type is inferred). If there is a current asset it will be released.

Parameters
idAssetId
queueLoadif true it will call "QueueLoad" to load the asset data.

◆ GetAutoLoadBehavior()

template<class T >
AssetLoadBehavior AZ::Data::Asset< T >::GetAutoLoadBehavior
Returns
auto load behavior for the asset reference.

◆ GetFlags()

template<class T >
u8 AZ::Data::Asset< T >::GetFlags

Returns asset instance flags Deprecated - use GetAutoLoadBehavior

◆ QueueLoad()

template<class T >
bool AZ::Data::Asset< T >::QueueLoad ( const AssetLoadParameters loadParams = {})

If the asset is not loaded and has a valid id, it will be queued for load.

Returns
true if the load was queued (you can listen on the AssetBus or check with IsReady) and false if the queue of loading did not happen. There are multiple reasons for this and you can test in case of error. Current failure conditions:
  • Invalid id

◆ Release()

template<class T >
bool AZ::Data::Asset< T >::Release

Releases reference on asset data, if one is held. The asset ID, hint, etc are all still preserved.

Returns
true if a reference was held, and therefore released.

◆ Reload()

template<class T >
bool AZ::Data::Asset< T >::Reload

Reloads an asset if an asset is create.

Returns
true if reload is triggered, otherwise false if an asset is not created (ie. We don't have asset ID to reload)

◆ Reset()

template<class T >
bool AZ::Data::Asset< T >::Reset

Fully resets the Asset to a clean initialized state. The asset data is released, the asset ID is reset, the hint is cleared, etc.

◆ Save()

template<class T >
bool AZ::Data::Asset< T >::Save

Save asset, triggers a SaveAsset of possible AssetDatabase::SaveAsset.

◆ SetAutoLoadBehavior()

template<class T >
void AZ::Data::Asset< T >::SetAutoLoadBehavior ( AssetLoadBehavior  loadBehavior)

Sets the auto load behavior for the asset reference.

Parameters

ref AssetLoadBehavior

◆ SetFlags()

template<class T >
bool AZ::Data::Asset< T >::SetFlags ( u8  flags)

You can change the flags only when we don't have an asset bound (ie. GetData() == null) Deprecated - use SetAutoLoadBehavior

◆ ToString() [1/2]

template<class T >
template<class StringType >
StringType AZ::Data::Asset< T >::ToString
inline

for debugging purposes - creates a string that represents the assets id, subid, hint, and name. You should use this function for any time you want to show the full details of an asset in a log message as it will always produce a consistent output string. By convention, don't surround the output of this call with any kind of decorator, (for example, don't format like [s]) because decorators are built-in.

◆ ToString() [2/2]

template<class T >
template<class StringType >
void AZ::Data::Asset< T >::ToString ( StringType &  result) const
inline

for debugging purposes only - updates a string that represents the asset's id, subid, hint and name. see comment details on StringType ToString() above.

◆ UpgradeAssetInfo()

template<class T >
void AZ::Data::Asset< T >::UpgradeAssetInfo

Upgrades legacy Ids/hints with the new canonical Ids/hints. This will search for the assetId and hint in the catalog and if found, will update it to be the new, canonical one(s)


The documentation for this class was generated from the following file: