class Object
package godot
implements IDisposable
extended by EditorFileSystemDirectory, EditorSelection, EditorVCSInterface, JNISingleton, JSONRPC, MainLoop, Node, Physics2DDirectBodyState, Physics2DDirectSpaceState, PhysicsDirectBodyState, PhysicsDirectSpaceState, Reference, TreeItem, UndoRedo
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 godot.Object.free method from your script or delete the instance from C++.
Some classes that extend Object add memory management. This is the case of godot.Reference, which counts references and deletes itself automatically when no longer referenced. godot.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 godot.Object._GetPropertyList and handled in godot.Object._Get and godot.Object._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".
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 godot.Object._Notification.
Note: Unlike references to a godot.Reference, references to an Object stored in a variable can become invalid without warning. Therefore, it's recommended to use godot.Reference for data classes instead of godot.Object.
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 godot.Reference.
Static variables
staticread onlyNOTIFICATION_POSTINITIALIZE:Int
Called right when the object is initialized. Not available in script.
Static methods
staticisInstanceValid(instance:Object):Bool
Returns whether instance is a valid object
(e.g. has not been deleted from memory).
Parameters:
instance | The instance to check. |
|---|
Returns:
If the instance is a valid object.
staticweakRef(obj:Object):WeakRef
Returns a weak reference to an object, or null
if the argument is invalid.
A weak reference to an object is not enough to keep the object alive:
when the only remaining references to a referent are weak references,
garbage collection is free to destroy the referent and reuse its memory
for something else. However, until the object is actually destroyed the
weak reference may return the object even if there are no strong references
to it.
Parameters:
obj | The object. |
|---|
Returns:
The godot.Object.weakRef reference to the object or null.
Constructor
Variables
Methods
_Get(property:String):Dynamic
Virtual method which can be overridden to customize the return value of godot.Object.get.
Returns the given property. Returns null if the property does not exist.
_GetPropertyList():Array
Virtual method which can be overridden to customize the return value of godot.Object.getPropertyList.
Returns the object's property list as an godot.Collections_Array of dictionaries.
Each property's godot.Collections_Dictionary must contain at least name: String and type: int (see godot.Variant_Type) entries. Optionally, it can also include hint: int (see godot.PropertyHint), hint_string: String, and usage: int (see godot.PropertyUsageFlags).
_Notification(what:Int):Void
Called whenever the object receives a notification, which is identified in what by a constant. The base godot.Object has two constants godot.Object.notificationPostinitialize and godot.Object.notificationPredelete, but subclasses such as godot.Node define a lot more notifications which are also received by this method.
_Set(property:String, value:Dynamic):Bool
Virtual method which can be overridden to customize the return value of godot.Object.set.
Sets a property. Returns true if the property exists.
addUserSignal(signal:String, ?arguments:Array):Void
Adds a user-defined signal. Arguments are optional, but can be added as an godot.Collections_Array of dictionaries, each containing name: String and type: int (see godot.Variant_Type) entries.
Parameters:
arguments | If the parameter is null, then the default value is new Godot.Collections.Array { } |
|---|
call(method:String, args:HaxeArray<Dynamic>):Dynamic
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("set", "position", Vector2(42.0, 0.0))
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).
callDeferred(method:String, args:HaxeArray<Dynamic>):Void
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:
call_deferred("set", "position", Vector2(42.0, 0.0))
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).
callv(method:String, argArray:Array):Dynamic
Calls the method on the object and returns the result. Contrarily to godot.Object.call, this method does not support a variable number of arguments but expects all parameters to be via a single godot.Collections_Array.
callv("set", [ "position", Vector2(42.0, 0.0) ])
canTranslateMessages():Bool
Returns true if the object can translate strings. See godot.Object.setMessageTranslation and godot.Object.tr.
connect(signal:String, target:Object, method:String, ?binds:Array, ?flags:UInt):Error
Connects a signal to a method on a target object. Pass optional binds to the call as an godot.Collections_Array of parameters. These parameters will be passed to the method after any parameter used in the call to godot.Object.emitSignal. Use flags to set deferred or one-shot connections. See godot.Object_ConnectFlags constants.
A signal can only be connected once to a method. It will print an error if already connected, unless the signal was connected with godot.Object_ConnectFlags.referenceCounted. To avoid this, first, use godot.Object.isConnected 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
An example of the relationship between binds passed to godot.Object.connect and parameters used when calling godot.Object.emitSignal:
connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # weapon_type and damage are passed last
emit_signal("hit", "Dark lord", 5) # "Dark lord" and 5 are passed first
func _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])
Parameters:
binds | If the parameter is null, then the default value is new Godot.Collections.Array { } |
|---|
disconnect(signal:String, target:Object, method:String):Void
Disconnects a signal from a method on the given target.
If you try to disconnect a connection that does not exist, the method will print an error. Use godot.Object.isConnected to ensure that the connection exists.
emitSignal(signal:String, args:HaxeArray<Dynamic>):Void
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:
emit_signal("hit", weapon_type, damage)
emit_signal("game_over")
free():Void
Deletes the object from memory immediately. For godot.Nodes, you may want to use godot.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.is_instance_valid before attempting to call its methods or access its properties.
get(property:String):Dynamic
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
Returns the object's class as a String. See also godot.Object.isClass.
Note: godot.Object.getClass does not take class_name declarations into account. If the object has a class_name defined, the base class name will be returned instead.
getIncomingConnections():Array
Returns an godot.Collections_Array of dictionaries with information about signals that are connected to the object.
Each godot.Collections_Dictionary contains three String entries:
-
sourceis a reference to the signal emitter. -
signal_nameis the name of the connected signal. -
method_nameis the name of the method to which the signal is connected.
getIndexed(property:NodePath):Dynamic
Gets the object's property indexed by the given godot.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".
Note: Even though the method takes godot.NodePath argument, it doesn't support actual paths to godot.Nodes in the scene tree, only colon-separated sub-property paths. For the purpose of nodes, use godot.Node.getNodeAndResource instead.
getInstanceId():UInt64
Returns the object's unique instance ID.
This ID can be saved in godot.EncodedObjectAsID, and can be used to retrieve the object instance with @GDScript.instance_from_id.
getMethodList():Array
Returns the object's methods and their signatures as an godot.Collections_Array.
getPropertyList():Array
Returns the object's property list as an godot.Collections_Array of dictionaries.
Each property's godot.Collections_Dictionary contain at least name: String and type: int (see godot.Variant_Type) entries. Optionally, it can also include hint: int (see godot.PropertyHint), hint_string: String, and usage: int (see godot.PropertyUsageFlags).
getSignalConnectionList(signal:String):Array
Returns an godot.Collections_Array of connections for the given signal.
hasUserSignal(signal:String):Bool
Returns true if the given user-defined signal exists. Only signals added using godot.Object.addUserSignal are taken into account.
isClass(class_:String):Bool
Returns true if the object inherits from the given class. See also godot.Object.getClass.
Note: godot.Object.isClass does not take class_name declarations into account. If the object has a class_name defined, godot.Object.isClass will return false for that name.
isConnected(signal:String, target:Object, method:String):Bool
Returns true if a connection exists for a given signal, target, and method.
isQueuedForDeletion():Bool
Returns true if the godot.Node.queueFree method was called for the object.
notification(what:Int, ?reversed:Bool):Void
Send a given notification to the object, which will also trigger a call to the godot.Object._Notification method of all classes that the object inherits from.
If reversed is true, godot.Object._Notification is called first on the object's own class, and then up to its successive parent classes. If reversed is false, godot.Object._Notification is called first on the highest ancestor (godot.Object itself), and then down to its successive inheriting classes.
propertyListChangedNotify():Void
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(name:String):Void
Removes a given entry from the object's metadata. See also godot.Object.setMeta.
set(property:String, value:Dynamic):Void
Assigns a new value to the given property. If the property 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).
setDeferred(property:String, value:Dynamic):Void
Assigns a new value to the given property, after the current frame's physics step. This is equivalent to calling godot.Object.set via godot.Object.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(property:NodePath, value:Dynamic):Void
Assigns a new value to the property identified by the godot.NodePath. 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)
setMessageTranslation(enable:Bool):Void
Defines whether the object can translate strings (with calls to godot.Object.tr). Enabled by default.
setMeta(name:String, value:Dynamic):Void
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 godot.Object.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(script:Reference):Void
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 method will be called.
toSignal(source:Object, signal:String):SignalAwaiter
Returns a new godot.SignalAwaiter awaiter configured to complete when the instance
source emits the signal specified by the signal parameter.
Parameters:
source | The instance the awaiter will be listening to. |
|---|---|
signal | The signal the awaiter will be waiting for. This sample prints a message once every frame up to 100 times. |
Returns:
A godot.SignalAwaiter that completes when
source emits the signal.
toString():String
tr(message:String):String
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 godot.Object.setMessageTranslation.