Resource
Base class for serializable objects.
Resource.swift:22class 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 Object
s in a Godot project, is also a resource, uniquely capable of storing and instantiating the Node
s 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
class RefCounted
Base class for reference-counted objects.
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 exampleGString
,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 (seeinstantiate(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 totrue
.func duplicate(subresources: Bool
) -> Resource? Duplicates this resource, returning a new resource with its
export
ed orPropertyUsageFlags/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 totrue
and the resource has been loaded from aPackedScene
instantiation, returns the rootNode
of the scene where this resource is used. Otherwise, returnsnull
.func getRid(
) -> RID Returns the
RID
of this resource (or an empty RID). Many resources (such asTexture2D
,Mesh
, and so on) are high-level abstractions of resources stored in a specialized server (DisplayServer
,RenderingServer
, etc.), so this function will return the originalRID
.func setupLocalToScene(
) Calls
_setupLocalToScene
. IfresourceLocalToScene
is set totrue
, this method is automatically called frominstantiate(editState:)
by the newly duplicated resource within the scene instance.func takeOverPath(String
) Sets the
resourcePath
topath
, 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
func _setupLocalToScene(
) Override this method to customize the newly duplicated resource created from
instantiate(editState:)
, if the original’sresourceLocalToScene
is set totrue
.
Subclasses
class Animation
Holds data that can be used to animate anything in the engine.
class AnimationLibrary
Container for
Animation
resources.class AnimationNode
Base class for
AnimationTree
nodes. Not related to scene nodes.class AnimationNodeStateMachinePlayback
Provides playback control for an
AnimationNodeStateMachine
.class AnimationNodeStateMachineTransition
A transition within an
AnimationNodeStateMachine
connecting twoAnimationRootNode
s.class AudioBusLayout
Stores information about the audio buses.
class AudioEffect
Audio effect for audio.
class AudioStream
Base class for audio streams.
class BitMap
Boolean matrix.
class BoneMap
Describes a mapping of bone names for retargeting
Skeleton3D
into common names defined by aSkeletonProfile
.class ButtonGroup
A group of buttons that doesn’t allow more than one button to be pressed at a time.
class CameraAttributes
Parent class for camera settings.
class CryptoKey
A cryptographic key (RSA).
class Curve
A mathematical curve.
class Curve2D
Describes a Bézier curve in 2D space.
class Curve3D
Describes a Bézier curve in 3D space.
class EditorNode3DGizmoPlugin
A class used by the editor to define Node3D gizmo types.
class EditorSettings
Object that holds the project-independent editor settings.
class Environment
Resource for environment nodes (like
WorldEnvironment
) that define multiple rendering options.class Font
Abstract base class for fonts and font variations.
class GDExtension
class GLTFAccessor
class GLTFAnimation
class GLTFBufferView
class GLTFCamera
Represents a GLTF camera.
class GLTFDocument
Class for importing and exporting glTF files in and out of Godot.
class GLTFDocumentExtension
GLTFDocument
extension class.class GLTFLight
Represents a GLTF light.
class GLTFMesh
class GLTFNode
GLTF node class.
class GLTFPhysicsBody
Represents a GLTF physics body.
class GLTFPhysicsShape
Represents a GLTF physics shape.
class GLTFSkeleton
class GLTFSkin
class GLTFSpecGloss
Archived GLTF extension for specular/glossy materials.
class GLTFState
Represents all data of a GLTF file.
class GLTFTexture
class GLTFTextureSampler
Represents a GLTF texture sampler
class Gradient
A color transition.
class Image
Image datatype.
class ImporterMesh
A
Resource
that contains vertex array-based geometry during the import process.class InputEvent
Abstract base class for input events.
class JSON
Helper class for creating and parsing JSON data.
class LabelSettings
Provides common settings to customize the text in a
Label
.class LightmapGIData
Contains baked lightmap and dynamic object probe data for
LightmapGI
.class Material
Virtual base class for applying visual properties to an object, such as color and roughness.
class Mesh
A
Resource
that contains vertex array-based geometry.class MeshLibrary
Library of meshes.
class MissingResource
An internal editor class intended for keeping the data of unrecognized resources.
class MultiMesh
Provides high-performance drawing of a mesh multiple times using GPU instancing.
class Noise
Abstract base class for noise generators.
class Occluder3D
Occluder shape resource for use with occlusion culling in
OccluderInstance3D
.class OccluderPolygon2D
Defines a 2D polygon for LightOccluder2D.
class OggPacketSequence
A sequence of Ogg packets.
class OpenXRAction
An OpenXR action.
class OpenXRActionMap
Collection of
OpenXRActionSet
andOpenXRInteractionProfile
resources for the OpenXR module.class OpenXRActionSet
Collection of
OpenXRAction
resources that make up an action set.class OpenXRIPBinding
Defines a binding between an
OpenXRAction
and an XR input or output.class OpenXRInteractionProfile
Suggested bindings object for OpenXR.
class PackedDataContainer
Efficiently packs and serializes
GArray
orGDictionary
.class PackedScene
An abstraction of a serialized scene.
class PhysicsMaterial
Holds physics-related properties of a surface, namely its roughness and bounciness.
class PolygonPathFinder
class RDShaderFile
Compiled shader file in SPIR-V form (used by
RenderingDevice
). Not to be confused with Godot’s ownShader
.class RDShaderSPIRV
SPIR-V intermediate representation as part of a
RDShaderFile
(used byRenderingDevice
).class RichTextEffect
A custom effect for a
RichTextLabel
.class SceneReplicationConfig
Configuration for properties to synchronize with a
MultiplayerSynchronizer
.class Script
A class stored as a resource.
class Shader
A shader implemented in the Godot shading language.
class ShaderInclude
A snippet of shader code to be included in a
Shader
with#include
.class Shape2D
Abstract base class for 2D shapes used for physics collision.
class Shape3D
Abstract base class for 3D shapes used for physics collision.
class Shortcut
A shortcut for binding input.
class SkeletonModification2D
Base class for resources that operate on
Bone2D
s in aSkeleton2D
.class SkeletonModificationStack2D
A resource that holds a stack of
SkeletonModification2D
s.class SkeletonProfile
Base class for a profile of a virtual skeleton used as a target for retargeting.
class Skin
class Sky
Defines a 3D environment’s background by using a
Material
.class SpriteFrames
Sprite frame library for AnimatedSprite2D and AnimatedSprite3D.
class StyleBox
Abstract base class for defining stylized boxes for UI elements.
class SyntaxHighlighter
Base class for syntax highlighters. Provides syntax highlighting data to a
TextEdit
.class Texture
Base class for all texture types.
class Theme
A resource used for styling/skinning
Control
s andWindow
s.class TileMapPattern
Holds a pattern to be copied from or pasted into
TileMap
s.class TileSet
Tile library for tilemaps.
class TileSetSource
Exposes a set of tiles for a
TileSet
resource.class Translation
A language translation that maps a collection of strings to their individual translations.
class VideoStream
Base resource for video streams.
class VideoStreamPlayback
Internal class used by
VideoStream
to manage playback state when played from aVideoStreamPlayer
.class VisualShaderNode
Base class for
VisualShader
nodes. Not related to scene nodes.class VoxelGIData
Contains baked voxel global illumination data for use in a
VoxelGI
node.class World2D
A resource that holds all components of a 2D world, such as a canvas and a physics space.
class World3D
A resource that holds all components of a 3D world, such as a visual scenario and a physics space.
class X509Certificate
An X509 certificate (e.g. for TLS).