Struct GodotObject
Base class for all non built-in types.
struct GodotObject
;
Every class which is not a built-in type inherits from this class.
You can construct Objects from scripting languages, using Object
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
:
var n = Node2D.new() print("position" in n) # Prints "True". print("other_property" in n) # Prints "False".
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
.
Methods
Name | Description |
---|---|
_get
|
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
|
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 ) entries. Optionally, it can also include hint: int (see propertyhint ), hint_string: String , and usage: int (see propertyusageflags ).
|
_init
|
Called when the object is initialized. |
_notification
|
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
|
Virtual method which can be overridden to customize the return value of set .
Sets a property. Returns true if the property exists.
|
_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 " .
|
addUserSignal
|
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 ) entries.
|
call
|
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
|
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
|
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
|
Returns true if the object can translate strings. See setMessageTranslation and tr .
|
connect
|
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
|
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
|
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
|
Deletes the object from memory. Any pre-existing reference to the freed object will now return null .
|
get
|
Returns the Variant value of the given property . If the property doesn't exist, this will return null .
|
getClass
|
Returns the object's class as a String .
|
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
|
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
|
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 .
|
getMeta
|
Returns the object's metadata entry for the given name .
|
getMetaList
|
Returns the object's metadata as a PoolStringArray .
|
getMethodList
|
Returns the object's methods and their signatures as an 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 ) entries. Optionally, it can also include hint: int (see propertyhint ), hint_string: String , and usage: int (see propertyusageflags ).
|
getScript
|
Returns the object's Script instance, or null if none is assigned.
|
getSignalConnectionList
|
Returns an Array of connections for the given signal .
|
getSignalList
|
Returns the list of signals as an Array of dictionaries.
|
hasMeta
|
Returns true if a metadata entry is found with the given name .
|
hasMethod
|
Returns true if the object contains the given method .
|
hasUserSignal
|
Returns true if the given user-defined signal exists.
|
isBlockingSignals
|
Returns true if signal emission blocking is enabled.
|
isClass
|
Returns true if the object inherits from the given class .
|
isConnected
|
Returns true if a connection exists for a given signal , target , and method .
|
isQueuedForDeletion
|
Returns true if the Node method was called for the object.
|
notification
|
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.
|
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
|
Removes a given entry from the object's metadata. |
set
|
Assigns a new value to the given property. If the property does not exist, nothing will happen.
|
setBlockSignals
|
If set to true , signal emission is blocked.
|
setDeferred
|
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) .
|
setIndexed
|
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
|
Defines whether the object can translate strings (with calls to tr ). Enabled by default.
|
setMeta
|
Adds or changes a given entry in the object's metadata. Metadata are serialized, and can take any Variant value.
|
setScript
|
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.
|
toString
|
Returns a String representing the object. If not overridden, defaults to " .
Override the method toString to customize the String representation.
|
tr
|
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 .
|
Enums
Name | Description |
---|---|
ConnectFlags
|
|
Constants
|