RSX Code Reference
    Preparing search index...

    Class Resources

    Runtime API for acquiring ResourceHandle objects and loading or unloading Resource instances.

    Use Resources.get to acquire a handle without guaranteeing that the resource is loaded. A handle remains valid while its resource is unloaded and exposes ResourceHandle#isLoaded, ResourceHandle#getLoadProgress, and ResourceHandle#value. Accessing ResourceHandle#value may perform a blocking load.

    Use Resources.load for a synchronous typed load, Resources.loadAsync for an asynchronous typed load, or Resources.loadHandleBackground to queue a background load and immediately receive a handle. Resource discovery and editor-side library mutations are provided by Editor.ProjectLibrary.

    Hierarchy (View Summary)

    Index
    • Deep-clones a loaded resource, assigns the clone a new UUID, and registers a loaded handle for it. The duplicate is not persisted to a package automatically.

      Parameters

      • resource: Resource

        Loaded resource to duplicate.

      Returns Resource

      The independent duplicate, or null if the input is null or not loaded.

      Thread safe.

    • 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.

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

      Type Parameters

      Parameters

      • type: ClassOf<T>

        Expected resource type.

      • uuid: UUID

        Unique identifier of the resource to load.

      • Optionalflags: EnumValue<ResourceLoadFlag>

        Optional flags used to control the load process.

      Returns T

      The loaded resource, or null if it cannot be found or does not match type.

      At runtime, the resource and its package must be included in the deployed build.

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

      Type Parameters

      Parameters

      Returns Promise<T>

      A promise that resolves to the loaded resource.

      At runtime, the resource and its package must be included in the deployed build.

    • Queues a background load for the resource with the specified UUID and immediately returns its ResourceHandle. If the resource is already loaded, the returned handle references the existing instance. Use ResourceHandle#isLoaded to determine when loading has completed and ResourceHandle#getLoadProgress to track its progress.

      Type Parameters

      Parameters

      • type: ClassOf<T>

        Expected resource type.

      • uuid: UUID

        Unique identifier of the resource to load.

      • Optionalflags: EnumValue<ResourceLoadFlag>

        Optional flags used to control the load process.

      Returns ResourceHandle<T>

      The resource handle, or null if the resource cannot be found.

      At runtime, the resource and its package must be included in the deployed build.

      The generic type is not verified because the resource may still be unloaded when this method returns. The caller must ensure that the UUID identifies the requested type. Use Resources.loadAsync when runtime type verification is required.

    • Releases an internal reference held by the resource system for the specified Resource or ResourceHandle. This allows a resource loaded with ResourceLoadFlag.KeepInternalRef to be unloaded after all external references are released.

      Parameters

      Returns void

      Call Resources.unloadUnused to release all resources that no longer have external references when fine-grained control is not required.

    • 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.

    • Replaces the object referenced by handle with a deep clone of resourceToClone. All copies of the target handle observe the replacement. The clone keeps the target handle's UUID and owns independent streaming data.

      Parameters

      • handle: Resource | ResourceHandle<Resource>

        Loaded target handle whose referenced object will be replaced.

      • resourceToClone: Resource

        Loaded resource to clone. Its runtime type must match the target resource type.

      Returns void

      Thread safe.

    onResourceDirtyChanged: Event<[resource: Resource, isDirty: boolean]>

    An event fired whenever a resource is marked as dirty.

    onResourceLoaded: Event<[resource: ResourceHandle<Resource>]>

    Triggered after a resource and its requested dependencies finish loading successfully.

    This event will be called from the main thread only.

    onResourceAppear: Event<[packageUUID: UUID, resourceUUID: UUID]>

    Triggered when package metadata makes a resource UUID available for loading.

    This event will be called from the main thread only.

    onResourceDisappear: Event<[packageUUID: UUID, resourceUUID: UUID]>

    Triggered when unloading or updating a package makes a resource UUID unavailable for future loads. An already loaded resource may remain alive until its references are released.

    This event will be called from the main thread only.

    onResourceDestroyed: Event<[resourceUUID: UUID]>

    Triggered after a loaded resource is destroyed and its handle data is cleared.

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

    onResourceHandleChanged: Event<[resource: ResourceHandle<Resource>]>

    Triggered after the object referenced by an existing handle is replaced. The handle keeps the same UUID.

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

    onResourceReverted: Event<[resource: ResourceHandle<Resource>]>

    Triggered after a resource handle is reverted to the representation stored in its package.

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