Class Resources

The Resources class provides APIs to dynamically load and unload Resource objects at runtime.

Hierarchy (view full)

Constructors

Methods

  • Duplicates the resource and creates a unique UUID for the duplicated resource.

    Parameters

    Returns Resource

    The duplicated resource or an empty handle if the duplicate failed.

    Thread safe.

  • Returns the loading progress of a Resource that's being asynchronously loaded.

    Parameters

    • resource: ResourceHandle<Resource>

      Resource whose load progress to check.

    • OptionalincludeDependencies: boolean

      If false the progress will reflect the load progress only for this individual resource. If true the progress will reflect load progress of this resource and all of its dependencies.

    Returns number

    Load progress in range [0, 1].

  • Checks is the specific animation resource dirty and needs saving.

    Parameters

    Returns boolean

    True if the resource requires saving, false otherwise.

  • Checks if the packages for the provided Resource and optionally its dependencies are present locally. They may not be present if running in online mode and they haven't been downloaded yet.

    Parameters

    Returns boolean

    True if all the requested packages are available locally.

  • Checks is the specific resource dirty and needs saving.

    Parameters

    Returns boolean

    True if the resource requires saving, false otherwise.

  • Loads a Resource from the specified path. If resource is already loaded an existing instance is returned.

    Type Parameters

    Parameters

    • type: ClassOf<T>

      The Type of the resource.

    • path: string

      Path of the resource, relative to game directory. If running from editor this will be relative to the project library. If a sub-resource within a file is needed, append the name of the subresource to the path (for example mymesh.fbx/my_animation).

    • Optionalflags: EnumValue<ResourceLoadFlag, number>

      Optional flags used to control the load process.

    Returns T

    Loaded resource, or null if resource cannot be found.

    If running outside of the editor you must make sure to mark that the resource gets included in the build. If running inside the editor this has similar functionality as if loading using the project library.

  • Loads a Resource with the specified UUID. If resource is already loaded an existing instance is returned.

    Type Parameters

    Parameters

    Returns T

    Loaded resource, or null if resource cannot be found.

    If running outside of the editor you must make sure to mark that the resource gets included in the build. If running inside the editor this has similar functionality as if loading using the project library.

  • Loads a Resource with the specified UUID asynchonously (on a separate thread). If resource is already loaded an existing instance is returned.

    Type Parameters

    Parameters

    Returns Promise<T>

    Promise that holds the loaded resource handle.

    If running outside of the editor you must make sure to mark that the resource gets included in the build. If running inside the editor this has similar functionality as if loading using the project library.

  • Loads a Resource from the specified path asynchonously in the background (on a separate thread). If resource is already loaded an existing instance is returned. Use ResourceHandle.isLoaded to confirm the resource has been loaded before using it. Use getLoadProgress to track the loading progress of the resource.

    Type Parameters

    Parameters

    • type: ClassOf<T>

      The Type of the resource.

    • path: string

      Path of the resource, relative to game directory. If running from editor this will be relative to the project library. If a sub-resource within a file is needed, append the name of the subresource to the path (for example mymesh.fbx/my_animation).

    • Optionalflags: EnumValue<ResourceLoadFlag, number>

      Optional flags used to control the load process.

    Returns ResourceHandle<T>

    Loaded resource, or null if resource cannot be found.

    If running outside of the editor you must make sure to mark that the resource gets included in the build. If running inside the editor this has similar functionality as if loading using the project library.

    This is load does not guarantee that the loaded resource matches the type as the load finishes in the background. The caller is responsible to ensure that the loaded resource matches the requested type. It is recommended to use loadAsync as an alternative API that provides type guarantees.

  • Loads a Resource with the specified UUID asynchonously in the background (on a separate thread). If resource is already loaded an existing instance is returned. Use ResourceHandle.isLoaded to confirm the resource has been loaded before using it. Use getLoadProgress to track the loading progress of the resource.

    Type Parameters

    Parameters

    • type: ClassOf<T>

      The Type of the resource.

    • uuid: UUID

      Unique identifier of the resource to load.

    • Optionalflags: EnumValue<ResourceLoadFlag, number>

      Optional flags used to control the load process.

    Returns ResourceHandle<T>

    Loaded resource, or null if resource cannot be found.

    If running outside of the editor you must make sure to mark that the resource gets included in the build. If running inside the editor this has similar functionality as if loading using the project library.

    This is load does not guarantee that the loaded resource matches the type as the load finishes in the background. The caller is responsible to ensure that the loaded resource matches the requested type. It is recommended to use loadAsync as an alternative API that provides type guarantees.

  • Releases an internal reference to the Resource held by the resources system. This allows the resource to be unloaded when it goes out of scope, if the resource was loaded with "keepLoaded" parameter.

    Parameters

    Returns void

    Alternatively you can also skip manually calling release and call unloadUnused which will unload all resources that do not have any external references, but you lose the fine grained control of what will be unloaded.

  • Discards all changes from a resource and re-downloads it from the cloud.

    Parameters

    • resource: Resource

      The resource to be reset and re-downloaded from the cloud.

    Returns AsyncOp<void, void>

    This API is asynchronous and will run in the background.

  • Marks a resource in the current project as clean.

    Parameters

    Returns void

  • Marks a resource in the current project as dirty.

    Parameters

    • resource: Resource

      Resource to mark as dirty.

    • OptionalisDirty: boolean

      Whether the resource is dirty or it should be marked as clean.

    Returns void

  • Checks if the resource should be cloned before queuing a save operation.

    Parameters

    • type: Type

      Type of the resource.

    Returns boolean

    True if the resource should be cloned.

  • Unloads all resources that are no longer referenced.

    Returns void

    This only applies to resources loaded with ResourceLoadFlag.KeepInternalRef flag, as all other resources will be unloaded when they go out of scope.

  • Updates an existing resource handle with a new resource. The handleToClone will be cloned to as new object for handle. Caller must ensure that new resource type matches the original resource type.

    Parameters

    Returns void

    Thread safe.

Events

onResourceDirtyChanged: Event<[Resource, boolean], void>

An event fired whenever a resource is marked as dirty.

onResourceLoaded: Event<[ResourceHandle<Resource>], void>

Called when the resource has been successfully loaded.

It's guaranteed that this event will be called from the main thread.

onResourceDestroyed: Event<[UUID], void>

Called when the resource has been destroyed. Provides UUID of the destroyed resource.

It's guaranteed that this event will be called from the main thread.

onResourceHandleChanged: Event<[ResourceHandle<Resource>], void>

Called when the internal resource the handle is pointing to has changed.

It's guaranteed that this event will be called from the main thread.

onResourceReverted: Event<[ResourceHandle<Resource>], void>

Called when the internal resource the handle is pointing to has been reverted.

It's guaranteed that this event will be called from the main thread.