Object
Category: Core
Base class for all non built-in types.
Methods
- script_changed ( )
Emitted whenever the object’s script is changed.
Enumerations
enum ConnectFlags:
- CONNECT_DEFERRED = 1 — Connect 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.
- 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.
Description
Every class which is not a built-in type inherits from this class.
You can construct Objects from scripting languages, using 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 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. , 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 and _set. However, scripting languages and C++ have simpler means to export them.
Objects also receive notifications. Notifications are a simple way to notify the object about different events, so they can all be handled together. See .
- Variant _get ( property ) virtual
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.
- _get_property_list ( ) virtual
Virtual method which can be overridden to customize the return value of get_property_list.
Returns the object’s property list as an of dictionaries.
Each property’s Dictionary must contain at least name: String
and type: int
(see ) entries. Optionally, it can also include hint: int
(see PropertyHint), hint_string: String
, and usage: int
(see ).
- void _init ( ) virtual
Called when the object is initialized.
- void _notification ( int what ) virtual
Called whenever the object receives a notification, which is identified in what
by a constant. The base has two constants NOTIFICATION_POSTINITIALIZE and , but subclasses such as Node define a lot more notifications which are also received by this method.
- _set ( String property, value ) virtual
Virtual method which can be overridden to customize the return value of set.
Sets a property. Returns true
if the property
exists.
- void add_user_signal ( signal, Array arguments=[ ] )
Adds a user-defined signal
. Arguments are optional, but can be added as an of dictionaries, each containing name: String
and type: int
(see Variant.Type) entries.
- call ( String method, … ) vararg
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:
call_deferred("set", "position", Vector2(42.0, 0.0))
- callv ( String method, 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 expected all parameters passed via a single .
- bool can_translate_messages ( ) const
Returns true
if the object can translate strings. See and tr.
Connects a signal
to a method
on a target
object. Pass optional binds
to the call as an of parameters. Use flags
to set deferred or one shot connections. See ConnectFlags constants.
A signal
can only be connected once to a . It will throw an error if already connected, unless the signal was connected with . To avoid this, first, use is_connected to check for existing connections.
If the target
is destroyed in the game’s lifecycle, the connection will be lost.
Examples:
connect("pressed", self, "_on_Button_pressed") # BaseButton signal
connect("text_entered", self, "_on_LineEdit_text_entered") # LineEdit signal
connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # User-defined signal
- void disconnect ( signal, Object target, 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 is_connected to ensure that the connection exists.
- emit_signal ( String signal, … ) vararg
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:
- void free ( )
Deletes the object from memory. Any pre-existing reference to the freed object will now return null
.
- get ( String property ) const
Returns the value of the given property
.
- String get_class ( ) const
Returns the object’s class as a .
- Array get_incoming_connections ( ) const
Returns an 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.
- get_indexed ( NodePath property ) const
Get the object’s property indexed by the given . 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"
.
- int get_instance_id ( ) const
Returns the object’s unique instance ID.
This ID can be saved in , and can be used to retrieve the object instance with @GDScript.instance_from_id.
- get_meta ( String name ) const
Returns the object’s metadata entry for the given name
.
- get_meta_list ( ) const
Returns the object’s metadata as a PoolStringArray.
- get_method_list ( ) const
Returns the object’s methods and their signatures as an Array.
Returns the object’s property list as an of dictionaries.
- Reference get_script ( ) const
Returns the object’s instance, or null
if none is assigned.
- Array get_signal_connection_list ( signal ) const
Returns an Array of connections for the given signal
.
- get_signal_list ( ) const
Returns the list of signals as an Array of dictionaries.
- has_meta ( String name ) const
Returns true
if a metadata entry is found with the given .
- has_method ( String method ) const
Returns true
if the object contains the given method
.
- has_user_signal ( String signal ) const
Returns true
if the given user-defined signal
exists.
- is_blocking_signals ( ) const
Returns true
if signal emission blocking is enabled.
- bool is_class ( class ) const
Returns true
if the object inherits from the given class
.
Returns true
if a connection exists for a given signal
, target
, and method
.
- bool is_queued_for_deletion ( ) const
Returns true
if the method was called for the object.
- void notification ( int what, 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.
If reversed
is true
, 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 ( itself), and then down to its successive inheriting classes.
- void property_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.
- void set ( String property, value )
Assigns a new value to the given property. If the property
does not exist, nothing will happen.
- void set_block_signals ( bool enable )
If set to true
, signal emission is blocked.
- void set_deferred ( property, Variant value )
Assigns a new value to the given property, after the current frame’s physics step. This is equivalent to calling via call_deferred, i.e. call_deferred("set", property, value)
.
- void set_indexed ( property, Variant value )
Assigns a new value to the property identified by the . 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)
- void set_message_translation ( bool enable )
Defines whether the object can translate strings (with calls to ). Default is true
.
- void set_meta ( String name, value )
Adds or changes a given entry in the object’s metadata. Metadata are serialized, and can take any Variant value.
Assigns a script to the object. Each object can have a single script assigned to it, which are used to extend its functionality.
- tr ( String message ) const
Translates a message using translation catalogs configured in the Project Settings.