ResourceLoader
Resource loading, shared cache and explicit background-request lifecycle.
ResourceLoader loads prepared resources rather than arbitrary source files. A loaded PackedEntity is not in the game tree yet: use Instantiate() and AddChild().
Reuse can return shared native data and the same C# wrapper. Do not Dispose it while other aliases use it. Ignore does not mean all external dependencies are independent; tested text-backend propagation uses IgnoreDeep/ReplaceDeep. Replace can update an already held object.
Background flow: LoadThreadedRequest() → poll status across frames → LoadThreadedGet(). Use the same path string and balance collections for repeated Requests. Early Get can block; this is not world streaming.
Complete background loader, external source files. Tests ran on Windows in isolated projects; failed loading, missing-dependency policy, import/export and GPU scenes were not executed here.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Properties1
SingletonProperty
public static ResourceLoaderInstance Singleton { get; }Borrowed wrapper of the global ResourceLoader, not a fresh loader per access. Do not Free()/Dispose() the engine-owned Singleton. Use static methods for ordinary operations; register ResourceFormatLoader separately.
Methods16
AddResourceFormatLoadervoid
public static void AddResourceFormatLoader(ResourceFormatLoader formatLoader, bool atFront = false);Adds an owned format loader to the global list; atFront=true gives priority over current handlers. Retain the instance until explicit unregistration. Repeating the same instance adds a duplicate rather than updating it; tested. Invalid objects/capacity exhaustion produce diagnostics with no separate Error. Do not register anew before each Load.
| Name | Type | Default |
|---|---|---|
formatLoader | ResourceFormatLoader | — |
atFront | bool | false |
formatLoaderThe same owned ResourceFormatLoader for registration/removal; track Add count.
atFrontTrue inserts before existing loaders; false appends.
Existsbool
public static bool Exists(string path, string typeHint = "");Checks cache/loader resource existence, not necessarily a valid disk file. A cached resource gives true even after file deletion and before typeHint filtering. A malformed file with a recognized extension can also give true without parsing. This guarantees neither successful Load<T>() nor a matching C# type; check loading separately.
| Name | Type | Default |
|---|---|---|
path | string | — |
typeHint | string | "" |
pathLoader-supported resource path; asset://, supported user:// or OS path, while uid:// requires a current registry. Keep the original string for threaded lifecycle.
typeHintOptional engine type name to select a loader; not C# typeof(T) or a guarantee about cached result type.
boolCache/loader answer; true guarantees no existing valid file or requested C# type.
GetCachedRefResource
public static Resource GetCachedRef(string path);Gets a cached Resource or null without loading a cache miss. Can return the same C# wrapper already used elsewhere, confirmed by ReferenceEquals. Early Dispose of that wrapper invalidates other managed aliases. Coordinate shared lifetime rather than independently disposing each alias. Not a clone or disk refresh.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathLoader-supported resource path; asset://, supported user:// or OS path, while uid:// requires a current registry. Keep the original string for threaded lifecycle.
ResourceCached Resource or null; possibly the same managed wrapper, not an independent copy.
GetDependenciesstring[]
public static string[] GetDependencies(string path);Collects declared external dependencies through format loaders, not a recursive loaded-object tree. An entry may be an ordinary path or UID::type::fallback record; the public wrapper does not add types, so the middle field can be empty. Do not pass a composite record directly to a filesystem API. Empty does not distinguish no dependencies from unsupported/failed format handling. Import, UID remaps and custom loaders can affect representation.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathLoader-supported resource path; asset://, supported user:// or OS path, while uid:// requires a current registry. Keep the original string for threaded lifecycle.
string[]Dependency-record array, not necessarily directly usable OS paths.
GetRecognizedExtensionsForTypestring[]
public static string[] GetRecognizedExtensionsForType(string type);Queries registered loaders for an engine type name, not C# System.Type. Empty can query the general set. Names have no leading dot; duplicates and plugin-registration changes are possible. The list proves no individual file existence, import state or validity.
| Name | Type | Default |
|---|---|---|
type | string | — |
typeEngine type name; empty for a general query. Not System.Type.
string[]Dotless extension names, possibly repeated.
GetResourceTypestring
public static string GetResourceType(string path);Asks loaders for resource type metadata by path and can perform I/O. Not a C# cast or full-load guarantee. A custom C# resource reported engine base type may differ from its managed class name. Empty means no recognized type, not a detailed Error.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathLoader-supported resource path; asset://, supported user:// or OS path, while uid:// requires a current registry. Keep the original string for threaded lifecycle.
stringEngine type name or empty when unrecognized.
GetResourceUidlong
public static long GetResourceUid(string path);Game runtime queries the ResourceUid reverse registry by normalized path, not every file UID header. Unknown paths return InvalidId. A stale reverse entry after SetId/RemoveId can return an ID without current HasId(). The editor uses a different loader path; editor scanning was not tested here.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathLoader-supported resource path; asset://, supported user:// or OS path, while uid:// requires a current registry. Keep the original string for threaded lifecycle.
longRegistry ID or InvalidId in runtime; file availability is separate.
HasCachedbool
public static bool HasCached(string path);Checks a normalized path entry in resource cache. Loads no file and validates no data freshness, disk existence or actual type. A held resource can stay cached after file deletion/change. Does not guarantee the entry survives after all owners release it.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathLoader-supported resource path; asset://, supported user:// or OS path, while uid:// requires a current registry. Keep the original string for threaded lifecycle.
boolTrue for a current cache entry, not a freshness/file check.
ListDirectorystring[]
public static string[] ListDirectory(string directoryPath);Lists immediate directory and recognized-resource names, not every physical file or a recursive tree. Directories end in /; .import/.remap/.uid sidecars collapse to the original name, with sorted deduplicated results. Extension recognition proves no valid parsing: a malformed .rdata appeared in the test. Empty can also follow directory-open/list-start failure. Export/import backends were not executed here.
| Name | Type | Default |
|---|---|---|
directoryPath | string | — |
directoryPathDirectory for immediate listing; not a glob or recursive query.
string[]Sorted unique names with / for directories; empty is also possible on failure.
Load2 overloads
public static Resource Load(string path, string typeHint = "", ResourceLoader.CacheMode cacheMode = ResourceLoader.CacheMode.Reuse);Synchronously obtains a Resource through its format and cache mode; failure can return null with engine diagnostics. Creates no Entity: PackedEntity still needs Instantiate()/AddChild(). Reuse can return the same native object and C# wrapper; do not Dispose a shared wrapper while other aliases use it. On the tested text backend Ignore creates an independent top resource but reuses external dependencies; IgnoreDeep loads those independently. Replace can refresh a held compatible-type object; ReplaceDeep also refreshes external dependencies. Disk changes do not automatically update Reuse. Custom loaders must account for cacheMode.
| Name | Type | Default |
|---|---|---|
path | string | — |
typeHint | string | "" |
cacheMode | ResourceLoader.CacheMode | ResourceLoader.CacheMode.Reuse |
pathLoader-supported resource path; asset://, supported user:// or OS path, while uid:// requires a current registry. Keep the original string for threaded lifecycle.
typeHintOptional engine type name to select a loader; not C# typeof(T) or a guarantee about cached result type.
cacheModeCache policy; ordinary Ignore/Replace in the text loader do not refresh external dependencies, deep modes propagate. Replace can change objects already in use.
ResourceResource or null; the generic overload additionally casts to T and can throw InvalidCastException.
public static T Load<T>(string path, string typeHint = null, ResourceLoader.CacheMode cacheMode = ResourceLoader.CacheMode.Reuse) where T : class;Synchronously obtains a Resource through its format and cache mode; failure can return null with engine diagnostics. Creates no Entity: PackedEntity still needs Instantiate()/AddChild(). Reuse can return the same native object and C# wrapper; do not Dispose a shared wrapper while other aliases use it. On the tested text backend Ignore creates an independent top resource but reuses external dependencies; IgnoreDeep loads those independently. Replace can refresh a held compatible-type object; ReplaceDeep also refreshes external dependencies. Disk changes do not automatically update Reuse. Custom loaders must account for cacheMode. The generic wrapper only casts the native result to T. It does not infer typeHint from T; a mismatch can throw InvalidCastException rather than return null.
| Name | Type | Default |
|---|---|---|
path | string | — |
typeHint | string | null |
cacheMode | ResourceLoader.CacheMode | ResourceLoader.CacheMode.Reuse |
pathLoader-supported resource path; asset://, supported user:// or OS path, while uid:// requires a current registry. Keep the original string for threaded lifecycle.
typeHintOptional engine type name to select a loader; not C# typeof(T) or a guarantee about cached result type.
cacheModeCache policy; ordinary Ignore/Replace in the text loader do not refresh external dependencies, deep modes propagate. Replace can change objects already in use.
TResource or null; the generic overload additionally casts to T and can throw InvalidCastException.
LoadThreadedGetResource
public static Resource LoadThreadedGet(string path);Collects one accepted user-request result. Can wait/block before completion; normally wait for Loaded first. After Failed also finish request lifecycle, expecting null and loader diagnostics. One call reduces request count; two identical Requests need two collections. After all are collected status becomes InvalidResource. With no request/already consumed it returns null; the Resource can be a shared cached wrapper.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathLoader-supported resource path; asset://, supported user:// or OS path, while uid:// requires a current registry. Keep the original string for threaded lifecycle.
ResourceResource result or null; can wait for completion and consumes one request.
LoadThreadedGetStatusResourceLoader.ThreadLoadStatus
public static ResourceLoader.ThreadLoadStatus LoadThreadedGetStatus(string path, Reckfell.Collections.Array progress = null);Returns status for the original request path string, not any equivalent OS path. InvalidResource can mean no request or all results already collected, not only a missing file. A supplied progress Array is overwritten with one 0…1 number, discarding existing elements; provide your own array. Use Loaded status, not progress alone, to decide ordinary collection. Do not busy-wait the main thread without frames.
| Name | Type | Default |
|---|---|---|
path | string | — |
progress | Reckfell.Collections.Array | null |
pathLoader-supported resource path; asset://, supported user:// or OS path, while uid:// requires a current registry. Keep the original string for threaded lifecycle.
progressOwned Array overwritten with one progress number; null omits this output.
ResourceLoader.ThreadLoadStatusInvalidResource, InProgress, Failed or Loaded; progress is no substitute.
LoadThreadedRequestError
public static Error LoadThreadedRequest(string path, string typeHint = "", bool useSubThreads = false, ResourceLoader.CacheMode cacheMode = ResourceLoader.CacheMode.Reuse);Starts/acquires a user request for background Resource loading. Error.Ok does not mean ready: poll LoadThreadedGetStatus() across frames, then collect with LoadThreadedGet(). Use exactly the same path string throughout. A repeated path can share a token and increase the required Get count; one Get does not clear two requests. Do not assume new flags on a repeated Request reconfigure the existing token. Not an async C# Task, cancellation API or world-streaming system.
| Name | Type | Default |
|---|---|---|
path | string | — |
typeHint | string | "" |
useSubThreads | bool | false |
cacheMode | ResourceLoader.CacheMode | ResourceLoader.CacheMode.Reuse |
pathLoader-supported resource path; asset://, supported user:// or OS path, while uid:// requires a current registry. Keep the original string for threaded lifecycle.
typeHintOptional engine type name to select a loader; not C# typeof(T) or a guarantee about cached result type.
useSubThreadsAllow distributed dependency loading where supported; not permission for arbitrary worker-thread EntityTree operations.
cacheModeCache policy; ordinary Ignore/Replace in the text loader do not refresh external dependencies, deep modes propagate. Replace can change objects already in use.
ErrorRequest-acceptance Error; Ok does not mean Loaded.
RemoveResourceFormatLoadervoid
public static void RemoveResourceFormatLoader(ResourceFormatLoader formatLoader);Removes the first registration of the instance. If added twice, one Remove leaves another entry; tested. Deletes no files and does not clear all cached resources. Remove all owned registrations before disposing the loader; missing/null instances produce diagnostics.
| Name | Type | Default |
|---|---|---|
formatLoader | ResourceFormatLoader | — |
formatLoaderThe same owned ResourceFormatLoader for registration/removal; track Add count.
SetAbortOnMissingResourcesvoid
public static void SetAbortOnMissingResources(bool abort);Changes global missing-dependency failure policy, not a per-Load option. The built-in text loader can continue with a missing dependency when false, without promising a usable resource or repaired schema. Abort concerns load failure, not a promise to terminate the game. Disables neither all parsing errors nor background requests. This pass source-reviewed the policy rather than executing damaged dependencies.
| Name | Type | Default |
|---|---|---|
abort | bool | — |
abortGlobal missing-dependency load-failure policy, not a switch eliminating every error.
ResourceLoader.CacheMode
| Value | Description |
|---|---|
Ignore = 0 | Neither the main resource (the one requested to be loaded) nor any of its subresources are retrieved from cache nor stored into it. Dependencies (external resources) are loaded with |
IgnoreDeep = 3 | Like |
Replace = 2 | Like |
ReplaceDeep = 4 | Like |
Reuse = 1 | The main resource (the one requested to be loaded), its subresources, and its dependencies (external resources) are retrieved from cache if present, instead of loaded. Those not cached are loaded and then stored into the cache. The same rules are propagated recursively down the tree of dependencies (external resources). |
ResourceLoader.ThreadLoadStatus
| Value | Description |
|---|---|
Failed = 2 | Some error occurred during loading and it failed. |
InProgress = 1 | The resource is still being loaded. |
InvalidResource = 0 | The resource is invalid, or has not been loaded with |
Loaded = 3 | The resource was loaded successfully and can be accessed via |