Skip to main content

Resource

Inherits: RefCounted < Object

Description

Base class for serializable objects. Resources are reference-counted and freed when no longer in use. They can be nested within other resources and saved on disk.

Inheritance

Resource < RefCounted < Object

Properties

resource_local_to_scene
bool
default:"false"
If true, the resource is duplicated for each instance of all scenes using it.
resource_name
String
default:""
An optional name for this resource. Displayed in the Inspector dock.
resource_path
String
default:""
The unique path to this resource. If saved to disk, the value will be its filepath.

Methods

duplicate

Resource duplicate(deep: bool = false)
Duplicates this resource, returning a new resource with its exported or PROPERTY_USAGE_STORAGE properties copied from the original.
deep
bool
If true, performs a deep copy where nested arrays and resources are also duplicated

emit_changed

void emit_changed()
Emits the changed signal. Call this method whenever a meaningful change occurs.

take_over_path

void take_over_path(path: String)
Sets the resource_path to path, potentially overriding an existing cache entry.

Signals

changed()

Emitted when the resource changes, usually when one of its properties is modified.

Example Usage

var resource = Resource.new()
resource.resource_name = "MyResource"

# Duplicate the resource
var copy = resource.duplicate()

# Connect to change signal
resource.changed.connect(func(): print("Resource changed"))
resource.emit_changed()

Build docs developers (and LLMs) love