Class Asset
Asset objects base class.
Inherited Members
Assembly: FlaxEngine.dll
File: Engine/Content/Asset.h
Syntax
public class Asset : public ManagedScriptingObject
Constructors
Asset(const SpawnParams& params, const AssetInfo* info)
Initializes a new instance of the Asset class.
Declaration
public Asset(const SpawnParams& params, const AssetInfo* info)
Parameters
SpawnParams
params
The object initialization parameters. |
AssetInfo
info
The asset object information. |
DECLARE_ENUM_7(LoadResult, Ok, Failed, MissingDataChunk, CannotLoadData, CannotLoadStorage, CannotLoadInitData, InvalidData)
The asset loading result.
Declaration
public DECLARE_ENUM_7(LoadResult, Ok, Failed, MissingDataChunk, CannotLoadData, CannotLoadStorage, CannotLoadInitData, InvalidData)
Parameters
LoadResult
Asset_DECLARE_ENUM_7_LoadResult_Ok_Failed_MissingDataChunk_CannotLoadData_CannotLoadStorage_CannotLoadInitData_InvalidData_
|
Ok
Asset_DECLARE_ENUM_7_LoadResult_Ok_Failed_MissingDataChunk_CannotLoadData_CannotLoadStorage_CannotLoadInitData_InvalidData_
|
Failed
Asset_DECLARE_ENUM_7_LoadResult_Ok_Failed_MissingDataChunk_CannotLoadData_CannotLoadStorage_CannotLoadInitData_InvalidData_
|
MissingDataChunk
Asset_DECLARE_ENUM_7_LoadResult_Ok_Failed_MissingDataChunk_CannotLoadData_CannotLoadStorage_CannotLoadInitData_InvalidData_
|
CannotLoadData
Asset_DECLARE_ENUM_7_LoadResult_Ok_Failed_MissingDataChunk_CannotLoadData_CannotLoadStorage_CannotLoadInitData_InvalidData_
|
CannotLoadStorage
Asset_DECLARE_ENUM_7_LoadResult_Ok_Failed_MissingDataChunk_CannotLoadData_CannotLoadStorage_CannotLoadInitData_InvalidData_
|
CannotLoadInitData
Asset_DECLARE_ENUM_7_LoadResult_Ok_Failed_MissingDataChunk_CannotLoadData_CannotLoadStorage_CannotLoadInitData_InvalidData_
|
InvalidData
Asset_DECLARE_ENUM_7_LoadResult_Ok_Failed_MissingDataChunk_CannotLoadData_CannotLoadStorage_CannotLoadInitData_InvalidData_
|
DEPRECATED("Use GetReferences with assets and files parameter instead")
Gets the asset references. Supported only in Editor. [Deprecated in v1.9]
For some asset types (e.g. scene or prefab) it may contain invalid asset ids due to not perfect gather method, which is optimized to perform scan very quickly. Before using those ids perform simple validation via Content cache API. The result collection contains only 1-level-deep references (only direct ones) and is invalid if asset is not loaded. Also, the output data may have duplicated asset ids or even invalid ids (Guid::Empty).
Declaration
public DEPRECATED("Use GetReferences with assets and files parameter instead") virtual void GetReferences(Array<Guid
Parameters
"Use GetReferences with assets and files parameter instead"
Asset_DEPRECATED__Use_GetReferences_with_assets_and_files_parameter_instead__
|
Fields
_deleteFileOnUnload
Declaration
protected int8 _deleteFileOnUnload
Field Value
int8
|
_isVirtual
Declaration
protected int8 _isVirtual
Field Value
int8
|
_loadingTask
Declaration
protected intptr _loadingTask
Field Value
intptr
|
_loadState
Declaration
protected int64 _loadState
Field Value
int64
|
_refCount
Declaration
protected int64 _refCount
Field Value
int64
|
const
Declaration
public HeapAllocationoutput const
Field Value
HeapAllocationoutput
|
Locker
General purpose mutex for an asset object. Should guard most of the asset functionalities to be secure.
Declaration
public CriticalSection Locker
Field Value
CriticalSection
|
OnLoaded
Action called when asset gets loaded
Declaration
public EventType OnLoaded
Field Value
EventType
|
OnReloading
Action called when asset start reloading (e.g. after reimport). Always called from the main thread.
Declaration
public EventType OnReloading
Field Value
EventType
|
OnUnloaded
Action called when asset gets unloaded
Declaration
public EventType OnUnloaded
Field Value
EventType
|
Methods
AddReference()
Adds reference to that asset.
Declaration
public void AddReference()
Returns
void
|
CancelStreaming()
Cancels any asynchronous content streaming by this asset (eg. mesh data streaming into GPU memory). Will release any locks for asset storage container.
Declaration
public virtual void CancelStreaming()
ChangeID(const Guid& newId)
Changes the object id (both managed and unmanaged). Warning! Use with caution as object ID is what it identifies it and change might cause issues.
Declaration
public virtual void ChangeID(const Guid& newId) override
Parameters
Guid
newId
The new ID. |
Overrides
createLoadingTask()
Creates the loading tasks sequence (allows to inject custom tasks to asset loading logic).
Declaration
protected virtual ContentLoadTask* createLoadingTask()
Returns
ContentLoadTask
First task to call on start loading |
CreateManaged()
Declaration
public virtual bool CreateManaged() override
Returns
bool
|
Overrides
DeleteManaged()
Deletes the managed object.
Declaration
public void DeleteManaged()
DestroyManaged()
Declaration
public virtual void DestroyManaged() override
Overrides
GetMemoryUsage()
Gets amount of CPU memory used by this resource (in bytes). It's a rough estimation. Memory may be fragmented, compressed or sub-allocated so the actual memory pressure from this resource may vary.
Declaration
public virtual uint64 GetMemoryUsage() const
Returns
uint64
|
GetPath()
Gets the path to the asset storage file. In Editor, it reflects the actual file, in cooked Game, it fakes the Editor path to be informative for developers.
Declaration
public virtual String GetPath() const = 0
Returns
String
|
GetReferences()
Gets the asset references. Supported only in Editor.
For some asset types (e.g. scene or prefab) it may contain invalid asset ids due to not perfect gather method, which is optimized to perform scan very quickly. Before using those ids perform simple validation via Content cache API. The result collection contains only 1-level-deep references (only direct ones) and is invalid if asset is not loaded. Also, the output data may have duplicated asset ids or even invalid ids (Guid::Empty).
Declaration
public Array<Guid, HeapAllocation> GetReferences() const
Returns
Array<Guid, HeapAllocation>
The collection of the asset ids referenced by this asset. |
GetReferences(Array<Guid, HeapAllocation>& assets, Array<String, HeapAllocation>& files)
Gets the asset references. Supported only in Editor.
For some asset types (e.g. scene or prefab) it may contain invalid asset ids due to not perfect gather method, which is optimized to perform scan very quickly. Before using those ids perform simple validation via Content cache API. The result collection contains only 1-level-deep references (only direct ones) and is invalid if asset is not loaded. Also, the output data may have duplicated asset ids or even invalid ids (Guid::Empty).
Declaration
public virtual void GetReferences(Array<Guid, HeapAllocation>& assets, Array<String, HeapAllocation>& files) const
Parameters
Array<Guid, HeapAllocation>
assets
The output collection of the asset ids referenced by this asset. |
Array<String, HeapAllocation>
files
The output list of file paths referenced by this asset. Files might come from project Content folder (relative path is preserved in cooked game), or external location (copied into Content root folder of cooked game). |
GetReferencesCount()
Gets asset's reference count. Asset will be automatically unloaded when this reaches zero.
Declaration
public int32 GetReferencesCount() const
Returns
int32
|
GetTypeName()
InitAsVirtual()
Initializes asset data as virtual asset.
Declaration
public virtual void InitAsVirtual()
IsInternalType()
Declaration
protected virtual bool IsInternalType() const
Returns
bool
|
IsLoaded()
Returns true if asset is loaded, otherwise false.
Declaration
public bool IsLoaded() const
Returns
bool
|
IsVirtual()
Determines whether this asset is virtual (generated or temporary, has no storage so it won't be saved).
Declaration
public bool IsVirtual() const
Returns
bool
|
LastLoadFailed()
Returns true if last asset loading failed, otherwise false.
Declaration
public bool LastLoadFailed() const
Returns
bool
|
loadAsset()
Loads asset
Declaration
protected virtual LoadResult loadAsset() = 0
Returns
LoadResult
Loading result |
OnCheckSave(const StringView& path=StringView::Empty)
Declaration
protected bool OnCheckSave(const StringView& path=StringView::Empty) const
Parameters
StringView
path
|
Returns
bool
|
OnDeleteObject()
Deletes the object. Called by the ObjectsRemovalService. Can be overriden to provide custom logic per object (cleanup, etc.).
Declaration
public virtual void OnDeleteObject() override
Overrides
onLoad(LoadAssetTask* task)
onLoaded()
Declaration
protected void onLoaded()
onLoaded_MainThread()
Declaration
protected virtual void onLoaded_MainThread()
OnManagedInstanceDeleted()
Declaration
public virtual void OnManagedInstanceDeleted() override
Overrides
onRename(const StringView& newPath)
Declaration
protected virtual void onRename(const StringView& newPath) = 0
Parameters
StringView
newPath
|
OnScriptingDispose()
Declaration
public virtual void OnScriptingDispose() override
Overrides
onUnload_MainThread()
Declaration
protected virtual void onUnload_MainThread()
releaseStorage()
Releases the storage file/container handle to prevent issues when renaming or moving the asset.
Declaration
protected virtual void releaseStorage()
Reload()
Reloads the asset.
Declaration
public void Reload()
RemoveReference()
Removes reference from that asset.
Declaration
public void RemoveReference()
Returns
void
|
Save(const StringView& path=StringView::Empty)
Saves this asset to the file. Supported only in Editor.
Declaration
public virtual bool Save(const StringView& path=StringView::Empty)
Parameters
StringView
path
The custom asset path to use for the saving. Use empty value to save this asset to its own storage location. Can be used to duplicate asset. Must be specified when saving virtual asset. |
Returns
bool
True when cannot save data, otherwise false. |
ShouldDeleteFileOnUnload()
Determines whether this asset was marked to be deleted on unload.
Declaration
public bool ShouldDeleteFileOnUnload() const
Returns
bool
|
startLoading()
Starts the asset loading.
Declaration
protected virtual void startLoading()
ToString()
Gets the string representation of this object.
Declaration
public virtual String ToString() const override
Returns
String
|
Overrides
unload(bool isReloading)
Unloads asset data
Declaration
protected virtual void unload(bool isReloading) = 0
Parameters
bool
isReloading
True if asset is reloading data, otherwise false. |
WaitForLoaded(double timeoutInMilliseconds=30000.0)
Stops the current thread execution and waits until asset will be loaded (loading will fail, success or be cancelled).
Declaration
public bool WaitForLoaded(double timeoutInMilliseconds=30000.0) const
Parameters
double
timeoutInMilliseconds
Custom timeout value in milliseconds. |
Returns
bool
True if cannot load that asset (failed or has been cancelled), otherwise false. |