Object

Inherited By:ARVRServer,AudioServer,CameraServer,ClassDB,EditorFileSystemDirectory,EditorNavigationMeshGenerator,EditorSelection,EditorVCSInterface,Engine,Geometry,GodotSharp,IP,Input,InputMap,JNISingleton,JSON,JSONRPC,JavaClassWrapper,JavaScript,MainLoop,Marshalls,Node,OS,Performance,Physics2DDirectBodyState,Physics2DDirectSpaceState,Physics2DServer,PhysicsDirectBodyState,PhysicsDirectSpaceState,PhysicsServer,ProjectSettings,Reference,ResourceLoader,ResourceSaver,TranslationServer,TreeItem,UndoRedo,VisualScriptEditor,VisualServer

Base class for all non-built-in types.

Description

Every class which is not a built-in type inherits from this class.

You can construct Objects from scripting languages, usingObject.new() in GDScript,newObject 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 thefree method from your script or delete the instance from C++.

Some classes that extend Object add memory management. This is the case ofReference, 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_get_property_list 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 usingin:

varn=Node2D.new()print("position"inn)# Prints "True".print("other_property"inn)# Prints "False".

Thein operator will evaluate totrue as long as the key exists, even if the value isnull.

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 aReference, references to an Object stored in a variable can become invalid without warning. Therefore, it's recommended to useReference for data classes instead ofObject.

Note: Due to a bug, you can't create a "plain" Object usingObject.new(). Instead, useClassDB.instance("Object"). This bug only applies to Object itself, not any of its descendents likeReference.

Tutorials

Methods

Variant

_get(String property)virtual

Array

_get_property_list()virtual

void

_init()virtual

void

_notification(int what)virtual

bool

_set(String property,Variant value)virtual

String

_to_string()virtual

void

add_user_signal(String signal,Array arguments=[ ])

Variant

call(String method, ...)vararg

void

call_deferred(String method, ...)vararg

Variant

callv(String method,Array arg_array)

bool

can_translate_messages()const

Error

connect(String signal,Object target,String method,Array binds=[ ],int flags=0)

void

disconnect(String signal,Object target,String method)

void

emit_signal(String signal, ...)vararg

void

free()

Variant

get(String property)const

String

get_class()const

Array

get_incoming_connections()const

Variant

get_indexed(NodePath property)const

int

get_instance_id()const

Variant

get_meta(String name)const

PoolStringArray

get_meta_list()const

Array

get_method_list()const

Array

get_property_list()const

Reference

get_script()const

Array

get_signal_connection_list(String signal)const

Array

get_signal_list()const

bool

has_meta(String name)const

bool

has_method(String method)const

bool

has_signal(String signal)const

bool

has_user_signal(String signal)const

bool

is_blocking_signals()const

bool

is_class(String class)const

bool

is_connected(String signal,Object target,String method)const

bool

is_queued_for_deletion()const

void

notification(int what,bool reversed=false)

void

property_list_changed_notify()

void

remove_meta(String name)

void

set(String property,Variant value)

void

set_block_signals(bool enable)

void

set_deferred(String property,Variant value)

void

set_indexed(NodePath property,Variant value)

void

set_message_translation(bool enable)

void

set_meta(String name,Variant value)

void

set_script(Reference script)

String

to_string()

String

tr(String message)const

Signals

  • script_changed()

Emitted whenever the object's script is changed.

Enumerations

enumConnectFlags:

  • CONNECT_DEFERRED =1 --- Connects a signal in deferred mode. This way, signal emissions are stored in a queue, then set on idle time.

  • CONNECT_PERSIST =2 --- Persisting connections are saved when the object is serialized to file.

  • CONNECT_ONESHOT =4 --- One-shot connections disconnect themselves after emission.

  • CONNECT_REFERENCE_COUNTED =8 --- Connect a signal as reference-counted. This means that a given signal can be connected several times to the same target, and will only be fully disconnected once no references are left.

Constants

  • NOTIFICATION_POSTINITIALIZE =0 --- Called right when the object is initialized. Not available in script.

  • NOTIFICATION_PREDELETE =1 --- Called before the object is about to be deleted.

Method Descriptions

Virtual method which can be overridden to customize the return value ofget.

Returns the given property. Returnsnull if theproperty does not exist.


Virtual method which can be overridden to customize the return value ofget_property_list.

Returns the object's property list as anArray of dictionaries.

Each property'sDictionary must contain at leastname:String andtype:int (seeVariant.Type) entries. Optionally, it can also includehint:int (seePropertyHint),hint_string:String, andusage:int (seePropertyUsageFlags).


Called when the object is initialized in memory. Can be defined to take in parameters, that are passed in when constructing.

Note: If_init is defined with required parameters, then explicit construction is the only valid means of creating an Object of the class. If any other means (such asPackedScene.instance) is used, then initialization will fail.


Called whenever the object receives a notification, which is identified inwhat by a constant. The baseObject has two constantsNOTIFICATION_POSTINITIALIZE andNOTIFICATION_PREDELETE, but subclasses such asNode define a lot more notifications which are also received by this method.


Virtual method which can be overridden to customize the return value ofset.

Sets a property. Returnstrue if theproperty exists.


Virtual method which can be overridden to customize the return value ofto_string, and thus the object's representation where it is converted to a string, e.g. withprint(obj).

Returns aString representing the object. If not overridden, defaults to"[ClassName:RID]".


Adds a user-definedsignal. Arguments are optional, but can be added as anArray of dictionaries, each containingname:String andtype:int (seeVariant.Type) entries.


Calls themethod 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:

Note: In C#, the method name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined methods where you should use the same convention as in the C# source (typically PascalCase).


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

Note: In C#, the method name must be specified as snake_case if it is defined by a built-in Godot node. This doesn't apply to user-defined methods where you should use the same convention as in the C# source (typically PascalCase).


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

callv("set",["position",Vector2(42.0,0.0)])

Returnstrue if the object can translate strings. Seeset_message_translation andtr.


Connects asignal to amethod on atarget object. Pass optionalbinds to the call as anArray of parameters. These parameters will be passed to the method after any parameter used in the call toemit_signal. Useflags to set deferred or one-shot connections. SeeConnectFlags constants.

Asignal can only be connected once to amethod. It will print an error if already connected, unless the signal was connected withCONNECT_REFERENCE_COUNTED. To avoid this, first, useis_connected to check for existing connections.

If thetarget is destroyed in the game's lifecycle, the connection will be lost.

Examples:

connect("pressed",self,"_on_Button_pressed")# BaseButton signalconnect("text_entered",self,"_on_LineEdit_text_entered")# LineEdit signalconnect("hit",self,"_on_Player_hit",[weapon_type,damage])# User-defined signal

An example of the relationship betweenbinds passed toconnect and parameters used when callingemit_signal:

connect("hit",self,"_on_Player_hit",[weapon_type,damage])# weapon_type and damage are passed lastemit_signal("hit","Dark lord",5)# "Dark lord" and 5 are passed firstfunc_on_Player_hit(hit_by,level,weapon_type,damage):print("Hit by%s (lvl%d) with weapon%s for%d damage"%[hit_by,level,weapon_type,damage])

Disconnects asignal from amethod on the giventarget.

If you try to disconnect a connection that does not exist, the method will print an error. Useis_connected to ensure that the connection exists.


Emits the givensignal. 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:


Deletes the object from memory immediately. ForNodes, you may want to useNode.queue_free 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 willnot be assigned tonull once the object is freed. Instead, it will point to apreviously freed instance and you should validate it with@GDScript.is_instance_valid before attempting to call its methods or access its properties.


Returns theVariant value of the givenproperty. If theproperty doesn't exist, this will returnnull.

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).


Returns the object's class as aString. See alsois_class.

Note:get_class does not takeclass_name declarations into account. If the object has aclass_name defined, the base class name will be returned instead.


Returns anArray of dictionaries with information about signals that are connected to the object.

EachDictionary 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.


Gets the object's property indexed by the givenNodePath. 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".

Note: Even though the method takesNodePath argument, it doesn't support actual paths toNodes in the scene tree, only colon-separated sub-property paths. For the purpose of nodes, useNode.get_node_and_resource instead.


Returns the object's unique instance ID.

This ID can be saved inEncodedObjectAsID, and can be used to retrieve the object instance with@GDScript.instance_from_id.


Returns the object's metadata entry for the givenname.


Returns the object's metadata as aPoolStringArray.


Returns the object's methods and their signatures as anArray.


Returns the object's property list as anArray of dictionaries.

Each property'sDictionary contain at leastname:String andtype:int (seeVariant.Type) entries. Optionally, it can also includehint:int (seePropertyHint),hint_string:String, andusage:int (seePropertyUsageFlags).


Returns the object'sScript instance, ornull if none is assigned.


Returns anArray of connections for the givensignal.


Returns the list of signals as anArray of dictionaries.


Returnstrue if a metadata entry is found with the givenname.


Returnstrue if the object contains the givenmethod.


Returnstrue if the givensignal exists.


Returnstrue if the given user-definedsignal exists. Only signals added usingadd_user_signal are taken into account.


Returnstrue if signal emission blocking is enabled.


Returnstrue if the object inherits from the givenclass. See alsoget_class.

Note:is_class does not takeclass_name declarations into account. If the object has aclass_name defined,is_class will returnfalse for that name.


Returnstrue if a connection exists for a givensignal,target, andmethod.


Returnstrue if theNode.queue_free method was called for the object.


  • voidnotification(int what,bool reversed=false)

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.

Ifreversed istrue,_notification is called first on the object's own class, and then up to its successive parent classes. Ifreversed isfalse,_notification is called first on the highest ancestor (Object itself), and then down to its successive inheriting classes.


  • voidproperty_list_changed_notify()

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.


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


Assigns a new value to the given property. If theproperty does not exist or the given value's type doesn't match, 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).


  • voidset_block_signals(bool enable)

If set totrue, signal emission is blocked.


Assigns a new value to the given property, after the current frame's physics step. This is equivalent to callingset viacall_deferred, 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).


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

set_indexed("position",Vector2(42,0))set_indexed("position:y",-10)print(position)# (42, -10)

  • voidset_message_translation(bool enable)

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


Adds, changes or removes a given entry in the object's metadata. Metadata are serialized and can take anyVariant value.

To remove a given entry from the object's metadata, useremove_meta. Metadata is also removed if its value is set tonull. This means you can also useset_meta("name",null) to remove metadata for"name".


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.


Returns aString representing the object. If not overridden, defaults to"[ClassName:RID]".

Override the method_to_string to customize theString representation.


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 themessage unchanged. Seeset_message_translation.