ResourceSaver
Resource saving through registered format handlers.
ResourceSaver.Save() saves a prepared Resource, not an arbitrary game tree. Resource, extension and registered savers select the format. .rdata is a text resource, .rbin binary; PackedEntity uses .rscene for levels and .rprefab for prefabs.
Check Error and backend capabilities. ChangePath has a reproduced failure-restoration limitation; SetUid() does not automatically update the runtime registry or form a transaction. Load compressed binary resources through ResourceLoader, not as ordinary archives.
Register an owned ResourceFormatSaver once and unregister before Dispose. The singleton belongs to the engine. Tests ran on Windows in an isolated process; editor callbacks, failed replacement and UID cache persistence across runs were not verified.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Properties1
SingletonProperty
public static ResourceSaverInstance Singleton { get; }Borrowed wrapper of the global engine service. Repeated access uses a cached managed wrapper, not a separate registry. Do not Free()/Dispose() this engine-owned object. Use the class static methods for ordinary work.
Methods6
AddResourceFormatSavervoid
public static void AddResourceFormatSaver(ResourceFormatSaver formatSaver, bool atFront = false);Adds an owned ResourceFormatSaver to the global list; atFront=true gives priority over current handlers. The registry retains a native reference, but manage registration and managed lifetime explicitly. Registering the same instance again creates a duplicate; do not add before each Save. Returns no Error; invalid objects/capacity exhaustion produce diagnostics. Unregister before disposing an owned saver.
| Name | Type | Default |
|---|---|---|
formatSaver | ResourceFormatSaver | — |
atFront | bool | false |
formatSaverOwned saver instance; retain it until explicit unregistration.
atFrontTrue inserts first; false appends after current handlers.
GetRecognizedExtensionsstring[]
public static string[] GetRecognizedExtensions(Resource type);Collects registered-saver extensions for a Resource instance; the type parameter is not C# typeof/a class name. Names have no dot; duplicates are possible and sorting is unspecified. The list guarantees no successful Save: a handler still checks recognition/path and may reject the operation. Contents depend on the resource and current plugin registration.
| Name | Type | Default |
|---|---|---|
type | Resource | — |
typeResource instance whose extensions are queried; not System.Type.
string[]New dotless-extension string[] with possible duplicates.
GetResourceIdForPathlong
public static long GetResourceIdForPath(string path, bool generate = false);Delegates a UID request to an optional callback, typically configured by the editor. Not ResourceUid.CreateIdForPath or a general UID factory. Without the callback it returns InvalidId even with generate=true, confirmed in a headless game process. Does not automatically inspect the whole file/registry or guarantee UID persistence.
| Name | Type | Default |
|---|---|---|
path | string | — |
generate | bool | false |
pathPath supplied to the callback, not uid:// text.
generateAllow generation by a supporting callback; without a callback still InvalidId.
longCallback UID or ResourceUid.InvalidId; generate=true guarantees no new value.
RemoveResourceFormatSavervoid
public static void RemoveResourceFormatSaver(ResourceFormatSaver formatSaver);Removes the first registration of that instance. If added twice, one Remove leaves another registration; tested. Does not automatically dispose your managed wrapper or delete saved files. Missing/null savers produce diagnostics; track whether Add occurred during normal lifecycle.
| Name | Type | Default |
|---|---|---|
formatSaver | ResourceFormatSaver | — |
formatSaverThe same registered instance; removes one registration.
SaveError
public static Error Save(Resource resource, string path = "", ResourceSaver.SaverFlags flags = ResourceSaver.SaverFlags.None);Saves a Resource through registered format savers: object and path are recognized before handler execution. Empty path uses ResourcePath; both empty is invalid. Failure can fall through to another handler; Ok is its report, not independent file verification. Concrete savers implement flags. In 1.0.0 ChangePath changes ResourcePath before calling and restores it only on success: failure can retain the new path, including after successful fallback. Reproduced. Not an atomic game save; a live Entity must be packed separately because Save takes a Resource.
| Name | Type | Default |
|---|---|---|
resource | Resource | — |
path | string | "" |
flags | ResourceSaver.SaverFlags | ResourceSaver.SaverFlags.None |
resourceLive Resource ready for the selected format; not a game-tree Entity.
pathDestination with a suitable extension; empty uses current ResourcePath. Validate parents/access separately.
flagsBackend SaverFlags; Compress/SaveBigEndian apply to the binary saver. ChangePath has the described failure-restoration limitation.
ErrorError from the last applicable handler; Ok is no independent write/atomicity certification.
SetUidError
public static Error SetUid(string resource, long uid);Asks a format saver to change an existing resource file UID; creates no game Entity and does not automatically register the path in ResourceUid. Check Error. The 1.0.0 text backend uses a temporary .uidren and remove/rename without propagating those replacement errors; a source-only limitation, not a transaction guarantee. Windows testing covered ordinary .rdata header changes, not replacement failures or editor scanning.
| Name | Type | Default |
|---|---|---|
resource | string | — |
uid | long | — |
resourcePath of an already saved resource file; a string, not a Resource object.
uidResource UID; validate validity/registration conflicts when managing it yourself.
ErrorHandler Error; text replacement does not validate every final filesystem operation.
ResourceSaver.SaverFlags
| Value | Description |
|---|---|
BundleResources = 2 | Bundles external resources. |
ChangePath = 4 | Changes the |
Compress = 32 | Compress the resource on save using |
None = 0 | No resource saving option. |
OmitEditorProperties = 8 | Do not save editor-specific metadata (identified by their |
RelativePaths = 1 | Save the resource with a path relative to the scene which uses it. |
ReplaceSubresourcePaths = 64 | Take over the paths of the saved subresources (see |
SaveBigEndian = 16 | Save as big endian (see |