GodotObject

Base class for all non-built-in types.

Every class which is not a built-in type inherits from this class. You can construct Objects from scripting languages, using Object.new() in GDScript, new Object in C#, or the "Construct Object" node in VisualScript. Objects do not manage memory. If a class inherits from Object, you will have to delete instances of it manually. To do so, call the free method from your script or delete the instance from C++. Some classes that extend Object add memory management. This is the case of Reference, which counts references and deletes itself automatically when no longer referenced. Node, another fundamental type, deletes all its children when freed from memory. Objects export properties, which are mainly useful for storage and editing, but not really so much in programming. Properties are exported in _getPropertyList and handled in _get and _set. However, scripting languages and C++ have simpler means to export them. Property membership can be tested directly in GDScript using in:

More...
@GodotBaseClass
struct GodotObject {}

Members

Aliases

BaseClasses
alias BaseClasses = AliasSeq!()
Undocumented in source.

Enums

ConnectFlags
enum ConnectFlags
Constants
enum Constants

Functions

_get
Variant _get(String property)

Virtual method which can be overridden to customize the return value of get. Returns the given property. Returns null if the property does not exist.

_getPropertyList
Array _getPropertyList()

Virtual method which can be overridden to customize the return value of getPropertyList. Returns the object's property list as an Array of dictionaries. Each property's Dictionary must contain at least name: String and type: int (see Variant.type) entries. Optionally, it can also include hint: int (see propertyhint), hint_string: String, and usage: int (see propertyusageflags).

_init
void _init()

Called when the object is initialized.

_notification
void _notification(long what)

Called whenever the object receives a notification, which is identified in what by a constant. The base GodotObject has two constants constant NOTIFICATION_POSTINITIALIZE and constant NOTIFICATION_PREDELETE, but subclasses such as Node define a lot more notifications which are also received by this method.

_set
bool _set(String property, VariantArg1 value)

Virtual method which can be overridden to customize the return value of set. Sets a property. Returns true if the property exists.

_toString
String _toString()

Virtual method which can be overridden to customize the return value of toString, and thus the object's representation where it is converted to a string, e.g. with print(obj). Returns a String representing the object. If not overridden, defaults to "$(D ClassName:RID)".

addUserSignal
void addUserSignal(String signal, Array arguments)

Adds a user-defined signal. Arguments are optional, but can be added as an Array of dictionaries, each containing name: String and type: int (see Variant.type) entries.

call
Variant call(String method, VarArgs varArgs)

Calls the method on the object and returns the result. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example:

callDeferred
void callDeferred(String method, VarArgs varArgs)

Calls the method on the object during idle time. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example:

callv
Variant callv(String method, Array arg_array)

Calls the method on the object and returns the result. Contrarily to call, this method does not support a variable number of arguments but expects all parameters to be via a single Array.

canTranslateMessages
bool canTranslateMessages()

Returns true if the object can translate strings. See setMessageTranslation and tr.

connect
GodotError connect(String signal, GodotObject target, String method, Array binds, long flags)

Connects a signal to a method on a target object. Pass optional binds to the call as an Array of parameters. These parameters will be passed to the method after any parameter used in the call to emitSignal. Use flags to set deferred or one-shot connections. See connectflags constants. A signal can only be connected once to a method. It will throw an error if already connected, unless the signal was connected with constant CONNECT_REFERENCE_COUNTED. To avoid this, first, use isConnected to check for existing connections. If the target is destroyed in the game's lifecycle, the connection will be lost.

disconnect
void disconnect(String signal, GodotObject target, String method)

Disconnects a signal from a method on the given target. If you try to disconnect a connection that does not exist, the method will throw an error. Use isConnected to ensure that the connection exists.

emitSignal
void emitSignal(String signal, VarArgs varArgs)

Emits the given signal. The signal must exist, so it should be a built-in signal of this class or one of its parent classes, or a user-defined signal. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example:

free
void free()

Deletes the object from memory immediately. For Nodes, you may want to use Node.queueFree to queue the node for safe deletion at the end of the current frame. Important: If you have a variable pointing to an object, it will not be assigned to null once the object is freed. Instead, it will point to a previously freed instance and you should validate it with @GDScript.isInstanceValid before attempting to call its methods or access its properties.

get
Variant get(String property)

Returns the Variant value of the given property. If the property doesn't exist, this will return null. Note: In C#, the property name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined properties where you should use the same convention as in the C# source (typically PascalCase).

getClass
String getClass()

Returns the object's class as a String.

getIncomingConnections
Array getIncomingConnections()

Returns an Array of dictionaries with information about signals that are connected to the object. Each Dictionary contains three String entries: - source is a reference to the signal emitter. - signal_name is the name of the connected signal. - method_name is the name of the method to which the signal is connected.

getIndexed
Variant getIndexed(NodePathArg0 property)

Gets the object's property indexed by the given NodePath. The node path should be relative to the current object and can use the colon character (:) to access nested properties. Examples: "position:x" or "material:next_pass:blend_mode".

getInstanceId
long getInstanceId()

Returns the object's unique instance ID. This ID can be saved in EncodedObjectAsID, and can be used to retrieve the object instance with @GDScript.instanceFromId.

getMeta
Variant getMeta(String name)

Returns the object's metadata entry for the given name.

getMetaList
PoolStringArray getMetaList()

Returns the object's metadata as a PoolStringArray.

getMethodList
Array getMethodList()

Returns the object's methods and their signatures as an Array.

getPropertyList
Array getPropertyList()

Returns the object's property list as an Array of dictionaries. Each property's Dictionary contain at least name: String and type: int (see Variant.type) entries. Optionally, it can also include hint: int (see propertyhint), hint_string: String, and usage: int (see propertyusageflags).

getScript
Ref!Reference getScript()

Returns the object's Script instance, or null if none is assigned.

getSignalConnectionList
Array getSignalConnectionList(String signal)

Returns an Array of connections for the given signal.

getSignalList
Array getSignalList()

Returns the list of signals as an Array of dictionaries.

hasMeta
bool hasMeta(String name)

Returns true if a metadata entry is found with the given name.

hasMethod
bool hasMethod(String method)

Returns true if the object contains the given method.

hasSignal
bool hasSignal(String signal)

Returns true if the given signal exists.

hasUserSignal
bool hasUserSignal(String signal)

Returns true if the given user-defined signal exists. Only signals added using addUserSignal are taken into account.

isBlockingSignals
bool isBlockingSignals()

Returns true if signal emission blocking is enabled.

isClass
bool isClass(String _class)

Returns true if the object inherits from the given class.

isConnected
bool isConnected(String signal, GodotObject target, String method)

Returns true if a connection exists for a given signal, target, and method.

isQueuedForDeletion
bool isQueuedForDeletion()

Returns true if the Node.queueFree method was called for the object.

notification
void notification(long what, bool reversed)

Send a given notification to the object, which will also trigger a call to the _notification method of all classes that the object inherits from. If reversed is true, _notification is called first on the object's own class, and then up to its successive parent classes. If reversed is false, _notification is called first on the highest ancestor (GodotObject itself), and then down to its successive inheriting classes.

opAssign
typeof(null) opAssign(typeof(null) n)
opCmp
int opCmp(GodotObject other)
opCmp
int opCmp(T other)
opEquals
bool opEquals(GodotObject other)
opEquals
bool opEquals(typeof(null) n)
propertyListChangedNotify
void propertyListChangedNotify()

Notify the editor that the property list has changed, so that editor plugins can take the new values into account. Does nothing on export builds.

removeMeta
void removeMeta(String name)

Removes a given entry from the object's metadata. See also setMeta.

set
void set(String property, VariantArg1 value)

Assigns a new value to the given property. If the property does not exist, nothing will happen. Note: In C#, the property name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined properties where you should use the same convention as in the C# source (typically PascalCase).

setBlockSignals
void setBlockSignals(bool enable)

If set to true, signal emission is blocked.

setDeferred
void setDeferred(String property, VariantArg1 value)

Assigns a new value to the given property, after the current frame's physics step. This is equivalent to calling set via callDeferred, i.e. call_deferred("set", property, value). Note: In C#, the property name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined properties where you should use the same convention as in the C# source (typically PascalCase).

setIndexed
void setIndexed(NodePathArg0 property, VariantArg1 value)

Assigns a new value to the property identified by the NodePath. The node path should be relative to the current object and can use the colon character (:) to access nested properties. Example:

setMessageTranslation
void setMessageTranslation(bool enable)

Defines whether the object can translate strings (with calls to tr). Enabled by default.

setMeta
void setMeta(String name, VariantArg1 value)

Adds, changes or removes a given entry in the object's metadata. Metadata are serialized and can take any Variant value. To remove a given entry from the object's metadata, use removeMeta. Metadata is also removed if its value is set to null. This means you can also use set_meta("name", null) to remove metadata for "name".

setScript
void setScript(Reference script)

Assigns a script to the object. Each object can have a single script assigned to it, which are used to extend its functionality. If the object already had a script, the previous script instance will be freed and its variables and state will be lost. The new script's _init method will be called.

toHash
size_t toHash()
toString
String toString()

Returns a String representing the object. If not overridden, defaults to "$(D ClassName:RID)". Override the method _toString to customize the String representation.

tr
String tr(String message)

Translates a message using translation catalogs configured in the Project Settings. Only works if message translation is enabled (which it is by default), otherwise it returns the message unchanged. See setMessageTranslation.

Mixins

__anonymous
mixin baseCasts
Undocumented in source.

Static functions

_new
GodotObject _new()

Construct a new instance of GodotObject. Note: use memnew!GodotObject instead.

Static variables

_classBindingInitialized
bool _classBindingInitialized;
Undocumented in source.

Structs

GDNativeClassBinding
struct GDNativeClassBinding
Undocumented in source.

Variables

_GODOT_internal_name
enum string _GODOT_internal_name;
Undocumented in source.
_godot_object
godot_object _godot_object;
Undocumented in source.

Mixed In Members

From mixin baseCasts

as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(ToRef) as()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(ToRef)
Undocumented in source.
opCast
void* opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
godot_object opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.

Detailed Description

var n = Node2D.new() print("position" in n) # Prints "True". print("other_property" in n) # Prints "False".

The in operator will evaluate to true as long as the key exists, even if the value is null. Objects also receive notifications. Notifications are a simple way to notify the object about different events, so they can all be handled together. See _notification. Note: Unlike references to a Reference, references to an Object stored in a variable can become invalid without warning. Therefore, it's recommended to use Reference for data classes instead of GodotObject. Note: Due to a bug, you can't create a "plain" Object using Object.new(). Instead, use ClassDB.instance("Object"). This bug only applies to Object itself, not any of its descendents like Reference.

Meta