Resource

    Base class for serializable objects.

    Resource.swift:22
    class Resource

    Resource is the base class for all Godot-specific resource types, serving primarily as data containers. Since they inherit from RefCounted, resources are reference-counted and freed when no longer in use. They can also be nested within other resources, and saved on disk. Once loaded from disk, further attempts to load a resource by resourcePath returns the same reference. PackedScene, one of the most common Objects in a Godot project, is also a resource, uniquely capable of storing and instantiating the Nodes it contains as many times as desired.

    In GDScript, resources can loaded from disk by their resourcePath using @GDScript.load or @GDScript.preload.

    This object emits the following signals:

    Superclasses

    Citizens in SwiftGodot

    Conformances

    • protocol CustomStringConvertible

      A type with a customized textual representation.

    • protocol Equatable

      A type that can be compared for value equality.

    • protocol Hashable

      A type that can be hashed into a Hasher to produce an integer hash value.

    • protocol Identifiable<ID>

      A class of types whose instances hold the value of an entity with stable identity.

    • protocol VariantRepresentable

      Types that conform to VariantRepresentable can be stored directly in Variant with no conversion. These include all of the Variant types from Godot (for example GString, Rect, Plane), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.

    • protocol VariantStorable

      Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.

    Type members

    Instance members

    • var changed: SimpleSignal

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

    • var resourceLocalToScene: Bool

      If true, the resource is duplicated for each instance of all scenes using it. At run-time, the resource can be modified in one scene without affecting other instances (see instantiate(editState:)).

    • var resourceName: String

      An optional name for this resource. When defined, its value is displayed to represent the resource in the Inspector dock. For built-in scripts, the name is displayed as part of the tab name in the script editor.

    • var resourcePath: String

      The unique path to this resource. If it has been saved to disk, the value will be its filepath. If the resource is exclusively contained within a scene, the value will be the PackedScene’s filepath, followed by a unique identifier.

    • var setupLocalToSceneRequested: SimpleSignal

      Emitted by a newly duplicated resource with resourceLocalToScene set to true.

    • func duplicate(subresources: Bool) -> Resource?

      Duplicates this resource, returning a new resource with its exported or PropertyUsageFlags/propertyUsageStorage properties copied from the original.

    • func emitChanged()

      Emits the [signal changed] signal. This method is called automatically for some built-in resources.

    • func getLocalScene() -> Node?

      If resourceLocalToScene is set to true and the resource has been loaded from a PackedScene instantiation, returns the root Node of the scene where this resource is used. Otherwise, returns null.

    • func getRid() -> RID

      Returns the RID of this resource (or an empty RID). Many resources (such as Texture2D, Mesh, and so on) are high-level abstractions of resources stored in a specialized server (DisplayServer, RenderingServer, etc.), so this function will return the original RID.

    • func setupLocalToScene()

      Calls _setupLocalToScene. If resourceLocalToScene is set to true, this method is automatically called from instantiate(editState:) by the newly duplicated resource within the scene instance.

    • func takeOverPath(String)

      Sets the resourcePath to path, potentially overriding an existing cache entry for this path. Further attempts to load an overridden resource by path will instead return this resource.

    Show implementation details (1)

    Hide implementation details

    Subclasses