Resource
Shared data, resource-graph copying and change notifications.
Resource stores data that multiple objects can share. Another C# variable does not create an independent copy. Duplicate() shares nested references; Duplicate(true) copies built-in resources; DuplicateDeep(All) includes external resources, with script and usage-flag exceptions.
ResourcePath manages a shared cache entry rather than saving a file. TakeOverPath() replaces path ownership; SetPathCache() is an internal operation without registration. Save changes separately through ResourceSaver. Do not Dispose a shared cached wrapper while other aliases still use it.
For a custom C# property call EmitChanged() after changing data: [Export] alone emits no automatic notification. ResourceLocalToScene concerns level/prefab handling rather than a separate copy per Entity.
Working with resources, custom format. Windows headless checks cover copy graphs, paths and callbacks. Editor ID caches, actual local PackedEntity instantiation and GPU RIDs were not executed here.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
ResourceConstructor
public Resource();Creates an owned Resource with empty path/name. Loads no file, registers no format and adds no Entity to a tree. Resources may be shared: choose the appropriate Duplicate mode for independent data rather than another variable pointing to the same object.
Properties4
ResourceLocalToSceneProperty
public bool ResourceLocalToScene { get; set; }Marks a resource for level/prefab instance-local handling by PackedEntity. Set before instantiation; changing the flag does not retroactively separate shared references. Not uniqueness per every Entity or a network ID. Actual PackedEntity handling was source-reviewed; a standalone flag assigning no GetLocalScene root was executed.
ResourceNameProperty
public string ResourceName { get; set; }Display name. Assignment emits Changed even for the same value; renames no file and does not change ResourcePath.
ResourcePathProperty
public string ResourcePath { get; set; }Path and shared-resource cache key, not a file-save command. The setter registers a nonempty path; empty unregisters it. For an occupied path use an intentional TakeOverPath or another path. Current native code rejects a collision after removing this object previous registration and clearing its path, so rollback is not promised. The collision branch was source-reviewed without executing the failing case.
ResourceSceneUniqueIdProperty
public string ResourceSceneUniqueId { get; set; }Local serialized-subresource ID. ASCII letters, digits, underscore and empty are allowed. An invalid character causes native diagnostics and replacement with a generated candidate rather than preserving the old value. Distinct from uid:// and project-wide uniqueness.
Methods26
CopyFromResourceError
public Error CopyFromResource(Resource resource);Copies STORAGE properties into the existing object while preserving its ResourcePath. Calls ResetState first; nested Resources remain shared rather than deeply copied. Checks the native engine class, not exact C# type equality. A mismatch returns InvalidParameter; null is also invalid. Changed emissions are batched into one pending notification if any occurred; Ok promises neither independent nested data nor disk persistence.
| Name | Type | Default |
|---|---|---|
resource | Resource | — |
resourceNonnull source with the same native engine class; nested data need not be independent.
ErrorOk for accepted copying or InvalidParameter for an invalid source/class; not proof of deep independence.
DuplicateResource
public Resource Duplicate(bool deep = false);Creates a new root Resource and copies stored properties/script, excluding ResourcePath. Containers and nested resources are shared by default. deep=true copies containers and built-in nested Resources; externally pathed resources normally remain shared. Repeated references to one duplicated resource point to one copy. Property usage flags can override the rule. Use DuplicateDeep(All) for external resources too; custom constructors/scripts can constrain duplication.
| Name | Type | Default |
|---|---|---|
deep | bool | false |
deepFalse shares containers/nested references; true recursively copies containers and built-in Resources subject to usage flags.
ResourceNew Resource under the selected depth rules; construction failure can yield null and diagnostics.
DuplicateDeepResource
public Resource DuplicateDeep(Resource.DeepDuplicateMode deepSubresourcesMode = Resource.DeepDuplicateMode.Internal);Creates a new root and recursively copies Array/Dictionary containers. None shares nested Resources; Internal duplicates built-in ones; All includes external Resources. All does not promise universal independence: scripts and NEVER_DUPLICATE properties may remain shared. A remap preserves repeated references within the copied graph rather than cloning every occurrence separately. Original Resource paths are not copied; nothing is saved to disk.
| Name | Type | Default |
|---|---|---|
deepSubresourcesMode | Resource.DeepDuplicateMode | Resource.DeepDuplicateMode.Internal |
deepSubresourcesModeNone, Internal or All: nested-Resource policy, not a switch disabling root/container copying.
ResourceNew root with the selected nested-resource policy; an invalid mode/construction failure can yield null.
EmitChangedvoid
public void EmitChanged();Notifies Changed subscribers after a data change. Writes no file and guarantees no refresh of every editor view. Call after an actual change in a custom C# setter; avoid recursively emitting from your own Changed handler. During background loading the native backend may defer notification to the main thread.
GenerateSceneUniqueIdstring
public static string GenerateSceneUniqueId();Creates a short five-character internal-ID candidate. Not a global UID, cryptographic identifier or uniqueness reservation. The current implementation uses a–y and 0–8; do not build a permanent public protocol around that detail. The saving caller handles collisions.
stringShort local-ID candidate, not a globally reserved UID.
GetIdForPathstring
public string GetIdForPath(string path);Reads the editor ID cache for the pair of referring file path and this resource current ResourcePath. Not ResourceUid or an ID read from an arbitrary file. Returns empty when absent or built without TOOLS_ENABLED. Editor persistence was source-reviewed only.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathReferring file path for the editor ID cache; not a new resource path.
stringCached ID for the path pair, or empty.
GetLocalSceneEntity
public Entity GetLocalScene();Returns the Entity root assigned by local-to-scene handling, an available editor context, or null. Setting ResourceLocalToScene=true alone neither creates nor assigns a root. The returned Entity is borrowed; do not Free it as your own temporary object. Actual PackedEntity instantiation was not executed in this pass.
EntityBorrowed root Entity or null.
GetNamestring
public string GetName();Returns ResourceName, a display name rather than a file path or global registry key.
stringCurrent display name, possibly empty.
GetPathstring
public string GetPath();Returns the current ResourcePath string. It may be empty, internal, or set with SetPathCache without registration. Nonempty does not prove a file exists, was loaded or was written.
stringCurrent path string without a file-existence guarantee.
GetRidRid
public Rid GetRid();Returns a backend-resource RID when provided by the concrete type. Base Resource returns an empty RID; not an InstanceId. Do not manually free a returned RID still owned by the Resource. IsValid checks a nonzero value, not suitability for every server API.
RidConcrete backend-resource RID or empty; not a newly owned object.
GetSceneUniqueIdstring
public string GetSceneUniqueId();Returns ResourceSceneUniqueId, a local serialized-subresource ID rather than global ResourceUid. Empty is permitted.
stringLocal serialized-subresource ID, possibly empty.
IsBuiltInbool
public bool IsBuiltIn();Classifies by path: empty, containing ::, or starting with local:// counts as built-in. Deep duplication uses this rule; it validates neither file presence, saving nor Entity ownership.
boolTrue under the built-in path-string classification.
IsLocalToScenebool
public bool IsLocalToScene();Returns the ResourceLocalToScene flag. True does not prove this instance has already been duplicated or assigned an Entity root.
boolCurrent local-to-scene flag.
ResetStatevoid
public void ResetState();Calls _ResetState for state the concrete class must clear itself. The base implementation does not automatically zero every exported property, name or path. CopyFromResource calls this hook before copying.
SetIdForPathvoid
public void SetIdForPath(string path, string id);Writes the editor ID cache for a referring file and current ResourcePath. Empty id removes the entry. Assigns no ResourceUid, saves no file and registers no new resource path. Does nothing without TOOLS_ENABLED; editor workflow was not executed here.
| Name | Type | Default |
|---|---|---|
path | string | — |
id | string | — |
pathReferring file path for the editor ID cache; not a new resource path.
idEditor-cache ID; empty removes the entry.
SetLocalToScenevoid
public void SetLocalToScene(bool enable);Sets ResourceLocalToScene. Creates no immediate copy, rewires no existing references and assigns no GetLocalScene root.
| Name | Type | Default |
|---|---|---|
enable | bool | — |
enableFlag for local-to-scene handling, not an immediate copy command.
SetNamevoid
public void SetName(string name);Sets ResourceName and emits Changed, including for the same value. Performs no file rename.
| Name | Type | Default |
|---|---|---|
name | string | — |
nameDisplay name; empty is allowed, not a file path.
SetPathvoid
public void SetPath(string path);Sets ResourcePath with ordinary cache registration. Writes/moves no file. A path occupied by another resource produces native diagnostics; current implementation has already cleared this object previous path at that point. Use TakeOverPath for intentional ownership replacement; SetPathCache has different raw-path semantics.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathNew path string; not a file write/move command. SetPathCache bypasses registration; SetPath/TakeOverPath change it.
SetPathCachevoid
public void SetPathCache(string path);Internally changes the path string and invokes _SetPathCache, bypassing ResourceCache registration. Not equivalent to ResourcePath/SetPath. Do not use to ordinarily move a cached object: this operation maintains no cache-entry consistency. Tested on an unregistered QA object.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathNew path string; not a file write/move command. SetPathCache bypasses registration; SetPath/TakeOverPath change it.
SetSceneUniqueIdvoid
public void SetSceneUniqueId(string id);Sets local ResourceSceneUniqueId. ASCII letters, digits and underscore are permitted; empty is accepted. For an invalid character native code assigns a generated ID and emits diagnostics. Writes no file and reserves no global uniqueness.
| Name | Type | Default |
|---|---|---|
id | string | — |
idLocal ID using ASCII letters, digits and underscore; empty is allowed.
SetupLocalToScenevoid · Deprecated
public void SetupLocalToScene();SDK-obsolete internal method. Emits SetupLocalToSceneRequested then calls _SetupLocalToScene. Does not itself duplicate the resource or enable local-to-scene. Override _SetupLocalToScene in ordinary user classes instead of manually calling this method; internal dispatch was exercised only by deliberate QA.
TakeOverPathvoid
public void TakeOverPath(string path);Assigns a resource path while replacing its cache owner. Existing references keep the previous owner alive, but its ResourcePath becomes empty. Subsequent path lookup points to this resource. Moves/saves no files; use only for intentional shared-object replacement.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathNew path string; not a file write/move command. SetPathCache bypasses registration; SetPath/TakeOverPath change it.
_GetRidRid
public virtual Rid _GetRid();Hook for the concrete resource GetRid. Return a RID of an actually owned backend object or an empty RID. Returning it creates no server object and transfers no ownership to the caller; do not substitute an InstanceId as a RID.
RidRID of the owned backend object, or empty.
_ResetStatevoid
public virtual void _ResetState();Override to clear your own nonstored/dynamic state. Called by ResetState, including before CopyFromResource. Do not recursively call ResetState from the hook; no automatic reset of all properties is provided.
_SetPathCachevoid
public virtual void _SetPathCache(string path);Notification after internal SetPathCache. The path is already assigned; the hook substitutes for neither ResourcePath registration nor file-operation confirmation. Do not recursively call SetPathCache here.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathNew path string; not a file write/move command. SetPathCache bypasses registration; SetPath/TakeOverPath change it.
_SetupLocalToScenevoid
public virtual void _SetupLocalToScene();Override to initialize a resource in local-to-scene handling. GetLocalScene can supply the assigned root; check for null outside normal instantiation. Not an every-Entity constructor or _Ready. Standalone callback dispatch was tested; actual PackedEntity local duplication was not executed in this pass.
Signals and events2
ChangedEvent
public event Action Changed;Change notification, not an automatic disk save. ResourceName emits even when assigned the same value. An ordinary custom C# [Export] setter does not emit automatically: call EmitChanged after a meaningful change. Shared references observe the same object.
SetupLocalToSceneRequestedEvent · Deprecated
public event Action SetupLocalToSceneRequested;SDK-obsolete: override _SetupLocalToScene for resource initialization instead of subscribing here. Native setup emits this event before the callback; the event itself proves neither duplication nor a level root.
Resource.DeepDuplicateMode
| Value | Description |
|---|---|
All = 2 | Every subresource found will be duplicated, even if it has a non-local path. In other words, even potentially big resources stored separately will be duplicated. |
Internal = 1 | Only subresources without a path or with a scene-local path will be duplicated. |
None = 0 | No subresources at all are duplicated. This is useful even in a deep duplication to have all the arrays and dictionaries duplicated but still pointing to the original resources. |