Object
Base class for all other classes in the engine.
Object.swift:38class Object
An advanced Variant
type. All classes in the engine inherit from Object. Each class may define new properties, methods or signals, which are available to all inheriting classes. For example, a Sprite2D
instance is able to call Node/addChild(node:forceReadableName:`internal`:)
because it inherits from Node
.
You can create new instances, using Object.new()
in GDScript, or new GodotObject
in C#.
To delete an Object instance, call free()
. This is necessary for most classes inheriting Object, because they do not manage memory on their own, and will otherwise cause memory leaks when no longer in use. There are a few classes that perform memory management. For example, RefCounted
(and by extension Resource
) deletes itself when no longer referenced, and Node
deletes its children when freed.
Objects can have a Script
attached to them. Once the Script
is instantiated, it effectively acts as an extension to the base class, allowing it to define and inherit new properties, methods and signals.
Inside a Script
, _getPropertyList()
may be overridden to customize properties in several ways. This allows them to be available to the editor, display as lists of options, sub-divide into groups, save on disk, etc. Scripting languages offer easier ways to customize properties, such as with the [annotation @GDScript.@export] annotation.
Godot is very dynamic. An object’s script, and therefore its properties, methods and signals, can be changed at run-time. Because of this, there can be occasions where, for example, a property required by a method may not exist. To prevent run-time errors, see methods such as set(property:value:)
, get(property:)
, call(method:)
, hasMethod(_:)
, hasSignal(_:)
, etc. Note that these methods are much slower than direct references.
In GDScript, you can also check if a given property, method, or signal name exists in an object with the in
operator:
Notifications are integer constants commonly sent and received by objects. For example, on every rendered frame, the SceneTree
notifies nodes inside the tree with a Node
notificationProcess````. The nodes receive it and may call _process(delta:)
to update. To make use of notifications, see ``notification(what:reversed:)`` and ``_notification()``.
Lastly, every object can also contain metadata (data about data). setMeta(name:value:)
can be useful to store information that the object itself does not depend on. To keep your code clean, making excessive use of metadata is discouraged.
This object emits the following signals:
Superclasses
class Wrapped
The base class for all class bindings in Godot, you should not have to instantiate or subclass this class directly - there are better options in the hierarchy.
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.
Types
Typealiases
Type members
static var godotType: Variant.GType
static let notificationPostinitialize: Int
Notification received when the object is initialized, before its script is attached. Used internally.
static let notificationPredelete: Int
Notification received when the object is about to be deleted. Can act as the deconstructor of some programming languages.
class var godotClassName: StringName
Instance members
var content: UnsafeRawPointer?
var description: String
var propertyListChanged: SimpleSignal
Emitted when
notifyPropertyListChanged
is called.var scriptChanged: SimpleSignal
Emitted when the object’s script is changed.
func addUserSignal(String, arguments: GArray
) Adds a user-defined
signal
. Optional arguments for the signal can be added as anGArray
of dictionaries, each defining aname
String
and atype
integer (seeVariant.GType
). See alsohasUserSignal(_:)
.func call(method: StringName, Variant...
) -> Variant Calls the
method
on the object and returns the result. This method supports a variable number of arguments, so parameters can be passed as a comma separated list.func callDeferred(method: StringName, Variant...
) -> Variant Calls the
method
on the object during idle time. Always returns null, not the method’s result.func callv(method: StringName, argArray: GArray
) -> Variant Calls the
method
on the object and returns the result. Unlikecall(method:)
, this method expects all parameters to be contained insideargArray
.func canTranslateMessages(
) -> Bool Returns
true
if the object is allowed to translate messages withtr(message:context:)
andtrN(message:pluralMessage:n:context:)
. See alsosetMessageTranslation(enable:)
.func cancelFree(
) If this method is called during
notificationPredelete
, this object will reject being freed and will remain allocated. This is mostly an internal function used for error handling to avoid the user from freeing objects when they are not intended to.func connect(signal: StringName, callable: Callable, flags: UInt32
) -> GodotError Connects a
signal
by name to acallable
. Optionalflags
can be also added to configure the connection’s behavior (seeConnectFlags
constants).func connect(signal: SignalWith1Argument<some Any>, to: some Object, method: String
) -> GodotError Connects a signal to a callable method
func connect(signal: SignalWith2Arguments<some Any, some Any>, to: some Object, method: String
) -> GodotError Connects a signal to a callable method
func connect(signal: SignalWith3Arguments<some Any, some Any, some Any>, to: some Object, method: String
) -> GodotError Connects a signal to a callable method
func connect(signal: SignalWith4Arguments<some Any, some Any, some Any, some Any>, to: some Object, method: String
) -> GodotError Connects a signal to a callable method
func connect(signal: SignalWith5Arguments<some Any, some Any, some Any, some Any, some Any>, to: some Object, method: String
) -> GodotError Connects a signal to a callable method
func connect(signal: SignalWith6Arguments<some Any, some Any, some Any, some Any, some Any, some Any>, to: some Object, method: String
) -> GodotError Connects a signal to a callable method
func connect(signal: SignalWithNoArguments, to: some Object, method: String
) -> GodotError Connects a signal to a callable method
func disconnect(signal: StringName, callable: Callable
) Disconnects a
signal
by name from a givencallable
. If the connection does not exist, generates an error. UseisConnected(signal:callable:)
to make sure that the connection exists.func emit(signal: SignalWithNoArguments
) -> GodotError Emits a signal that was previously defined with the #signal macro.
func emit<A>(signal: SignalWith1Argument<A>, A
) -> GodotError Emits a signal that was previously defined with the #signal macro. The argument must match the type of the argument at that position in the signal.
func emit<A, B>(signal: SignalWith2Arguments<A, B>, A, B
) -> GodotError Emits a signal that was previously defined with the #signal macro. The argument must match the type of the argument at that position in the signal.
func emit<A, B, C>(signal: SignalWith3Arguments<A, B, C>, A, B, C
) -> GodotError Emits a signal that was previously defined with the #signal macro. The argument must match the type of the argument at that position in the signal.
func emit<A, B, C, D>(signal: SignalWith4Arguments<A, B, C, D>, A, B, C, D
) -> GodotError Emits a signal that was previously defined with the #signal macro. The argument must match the type of the argument at that position in the signal.
func emit<A, B, C, D, E>(signal: SignalWith5Arguments<A, B, C, D, E>, A, B, C, D, E
) -> GodotError Emits a signal that was previously defined with the #signal macro. The argument must match the type of the argument at that position in the signal.
func emit<A, B, C, D, E, F>(signal: SignalWith6Arguments<A, B, C, D, E, F>, A, B, C, D, E, F
) -> GodotError Emits a signal that was previously defined with the #signal macro. The argument must match the type of the argument at that position in the signal.
func emitSignal(StringName, Variant...
) -> GodotError Emits the given
signal
by name. The signal must exist, so it should be a built-in signal of this class or one of its inherited classes, or a user-defined signal (seeaddUserSignal(_:arguments:)
). This method supports a variable number of arguments, so parameters can be passed as a comma separated list.func get(property: StringName
) -> Variant Returns the
Variant
value of the givenproperty
. If theproperty
does not exist, this method returnsnull
.func getClass(
) -> String Returns the object’s built-in class name, as a
String
. See alsoisClass(_:)
.func getIncomingConnections(
) -> VariantCollection<GDictionary> Returns an
GArray
of signal connections received by this object. Each connection is represented as aGDictionary
that contains three entries:func getIndexed(propertyPath: NodePath
) -> Variant Gets the object’s property indexed by the given
propertyPath
. The path should be aNodePath
relative to the current object and can use the colon character (:
) to access nested properties.func getInstanceId(
) -> UInt Returns the object’s unique instance ID. This ID can be saved in
EncodedObjectAsID
, and can be used to retrieve this object instance with@GlobalScope.instance_from_id
.func getMeta(name: StringName, default: Variant
) -> Variant Returns the object’s metadata value for the given entry
name
. If the entry does not exist, returnsdefault
. Ifdefault
isnull
, an error is also generated.func getMetaList(
) -> VariantCollection<StringName> Returns the object’s metadata entry names as a
PackedStringArray
.func getMethodList(
) -> VariantCollection<GDictionary> Returns this object’s methods and their signatures as an
GArray
of dictionaries. EachGDictionary
contains the following entries:func getPropertyList(
) -> VariantCollection<GDictionary> Returns the object’s property list as an
GArray
of dictionaries. EachGDictionary
contains the following entries:func getScript(
) -> Variant Returns the object’s
Script
instance, ornull
if no script is attached.func getSignalConnectionList(signal: StringName
) -> VariantCollection<GDictionary> Returns an
GArray
of connections for the givensignal
name. Each connection is represented as aGDictionary
that contains three entries:func getSignalList(
) -> VariantCollection<GDictionary> Returns the list of existing signals as an
GArray
of dictionaries.func hasMeta(name: StringName
) -> Bool Returns
true
if a metadata entry is found with the givenname
. See alsogetMeta(name:`default`:)
,setMeta(name:value:)
andremoveMeta(name:)
.func hasMethod(StringName
) -> Bool Returns
true
if the givenmethod
name exists in the object.func hasSignal(StringName
) -> Bool Returns
true
if the givensignal
name exists in the object.func hasUserSignal(StringName
) -> Bool Returns
true
if the given user-definedsignal
name exists. Only signals added withaddUserSignal(_:arguments:)
are included.func isBlockingSignals(
) -> Bool Returns
true
if the object is blocking its signals from being emitted. SeesetBlockSignals(enable:)
.func isClass(String
) -> Bool Returns
true
if the object inherits from the givenclass
. See alsogetClass
.func isConnected(signal: StringName, callable: Callable
) -> Bool Returns
true
if a connection exists between the givensignal
name andcallable
.func isQueuedForDeletion(
) -> Bool Returns
true
if thequeueFree
method was called for the object.func notification(what: Int32, reversed: Bool
) Sends the given
what
notification to all classes inherited by the object, triggering calls to_notification()
, starting from the highest ancestor (theObject
class) and going down to the object’s script.func notifyPropertyListChanged(
) Emits the [signal property_list_changed] signal. This is mainly used to refresh the editor, so that the Inspector and editor plugins are properly updated.
func propertyCanRevert(property: StringName
) -> Bool Returns
true
if the givenproperty
has a custom default value. UsepropertyGetRevert(property:)
to get theproperty
’s default value.func propertyGetRevert(property: StringName
) -> Variant Returns the custom default value of the given
property
. UsepropertyCanRevert(property:)
to check if theproperty
has a custom default value.func removeMeta(name: StringName
) Removes the given entry
name
from the object’s metadata. See alsohasMeta(name:)
,getMeta(name:`default`:)
andsetMeta(name:value:)
.func set(property: StringName, value: Variant
) Assigns
value
to the givenproperty
. If the property does not exist or the givenvalue
‘s type doesn’t match, nothing happens.func setBlockSignals(enable: Bool
) If set to
true
, the object becomes unable to emit signals. As such,emitSignal(_:)
and signal connections will not work, until it is set tofalse
.func setDeferred(property: StringName, value: Variant
) Assigns
value
to the givenproperty
, at the end of the current frame. This is equivalent to callingset(property:value:)
throughcallDeferred(method:)
.func setIndexed(propertyPath: NodePath, value: Variant
) Assigns a new
value
to the property identified by thepropertyPath
. The path should be aNodePath
relative to this object, and can use the colon character (:
) to access nested properties.func setMessageTranslation(enable: Bool
) If set to
true
, allows the object to translate messages withtr(message:context:)
andtrN(message:pluralMessage:n:context:)
. Enabled by default. See alsocanTranslateMessages
.func setMeta(name: StringName, value: Variant
) Adds or changes the entry
name
inside the object’s metadata. The metadatavalue
can be anyVariant
, although some types cannot be serialized correctly.func setScript(Variant
) Attaches
script
to the object, and instantiates it. As a result, the script’s_init()
is called. AScript
is used to extend the object’s functionality.func toString(
) -> String Returns a
String
representing the object. Defaults to"<ClassName#RID>"
. Override_toString()
to customize the string representation of the object.func tr(message: StringName, context: StringName
) -> String Translates a
message
, using the translation catalogs configured in the Project Settings. Furthercontext
can be specified to help with the translation.func trN(message: StringName, pluralMessage: StringName, n: Int32, context: StringName
) -> String Translates a
message
orpluralMessage
, using the translation catalogs configured in the Project Settings. Furthercontext
can be specified to help with the translation.
Type features
init?(Variant
) static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant.
static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant. This is useful when you want one method to call that will return the unwrapped Variant, regardless of whether it is a SwiftGodot.Object or not.
Instance features
Subclasses
class AudioServer
Server interface for low-level audio access.
class CameraServer
Server keeping track of different cameras accessible in Godot.
class ClassDB
A class information repository.
class DisplayServer
A server interface for low-level window management.
class EditorFileSystemDirectory
A directory for the resource filesystem.
class EditorInterface
Godot editor’s interface.
class EditorPaths
Editor-only singleton that returns paths to various OS-specific data folders and files.
class EditorSelection
Manages the SceneTree selection in the editor.
class EditorUndoRedoManager
Manages undo history of scenes opened in the editor.
class EditorVCSInterface
Version Control System (VCS) interface, which reads and writes to the local VCS in use.
class Engine
Provides access to engine properties.
class EngineDebugger
Exposes the internal debugger.
class GDExtensionManager
This object emits the following signals:
class Geometry2D
Provides methods for some common 2D geometric operations.
class Geometry3D
Provides methods for some common 3D geometric operations.
class IP
Internet protocol (IP) support functions such as DNS resolution.
class Input
A singleton for handling inputs.
class InputMap
A singleton that manages all
InputEventAction
s.class JNISingleton
Singleton that connects the engine with Android plugins to interface with native Android code.
class JSONRPC
A helper to handle dictionaries which look like JSONRPC documents.
class JavaClassWrapper
class JavaScriptBridge
Singleton that connects the engine with the browser’s JavaScript context in Web export.
class MainLoop
Abstract base class for the game’s main loop.
class Marshalls
Data transformation (marshaling) and encoding helpers.
class MovieWriter
Abstract class for non-real-time video recording encoders.
class Node
Base class for all scene objects.
class OS
Provides access to common operating system functionalities.
class OpenXRExtensionWrapperExtension
Allows clients to implement OpenXR extensions with GDExtension.
class OpenXRInteractionProfileMetadata
Meta class registering supported devices in OpenXR.
class Performance
Exposes performance-related data.
class PhysicsDirectBodyState2D
Provides direct access to a physics body in the
PhysicsServer2D
.class PhysicsDirectBodyState3D
Provides direct access to a physics body in the
PhysicsServer3D
.class PhysicsDirectSpaceState2D
Provides direct access to a physics space in the
PhysicsServer2D
.class PhysicsDirectSpaceState3D
Provides direct access to a physics space in the
PhysicsServer3D
.class PhysicsServer2D
A server interface for low-level 2D physics access.
class PhysicsServer2DManager
A singleton for managing
PhysicsServer2D
implementations.class PhysicsServer3D
A server interface for low-level 3D physics access.
class PhysicsServer3DManager
A singleton for managing
PhysicsServer3D
implementations.class PhysicsServer3DRenderingServerHandler
A class used to provide
_softBodyUpdateRenderingServer(body:renderingServerHandler:)
with a rendering handler for soft bodies.class ProjectSettings
Stores globally-accessible variables.
class RefCounted
Base class for reference-counted objects.
class RenderingDevice
Abstraction for working with modern low-level graphics APIs.
class RenderingServer
Server for anything visible.
class ResourceLoader
A singleton for loading resource files.
class ResourceSaver
A singleton for saving
Resource
s to the filesystem.class ResourceUID
A singleton that manages the unique identifiers of all resources within a project.
class ScriptLanguage
class SignalProxy
This is a convenience object used as a helper for signals, all it does is register a method with godot called
proxy
that will invoke the callback defined in the publicproxy
variable here.class TextServerManager
A singleton for managing
TextServer
implementations.class ThemeDB
A singleton that provides access to static information about
Theme
resources used by the engine and by your project.class TileData
Settings for a single tile in a
TileSet
.class Time
A singleton for working with time data.
class TranslationServer
The server responsible for language translations.
class TreeItem
An internal control for a single item inside
Tree
.class UndoRedo
Provides a high-level interface for implementing undo and redo operations.
class WorkerThreadPool
A singleton that allocates some
Thread
s on startup, used to offload tasks to these threads.class XRServer
Server for AR and VR features.