godot/doc/classes/Object.xml

626 lines
34 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="UTF-8" ?>
<class name="Object" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
2021-03-18 11:04:28 +00:00
Base class for all non-built-in types.
</brief_description>
<description>
Every class which is not a built-in type inherits from this class.
You can construct Objects from scripting languages, using [code]Object.new()[/code] in GDScript, [code]new Object[/code] 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 free] method from your script or delete the instance from C++.
2021-06-04 16:03:15 +00:00
Some classes that extend Object add memory management. This is the case of [RefCounted], 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 [method _get_property_list] and handled in [method _get] and [method _set]. However, scripting languages and C++ have simpler means to export them.
Property membership can be tested directly in GDScript using [code]in[/code]:
[codeblocks]
[gdscript]
var n = Node2D.new()
print("position" in n) # Prints "true".
print("other_property" in n) # Prints "false".
[/gdscript]
[csharp]
var node = new Node2D();
// C# has no direct equivalent to GDScript's `in` operator here, but we
// can achieve the same behavior by performing `Get` with a null check.
GD.Print(node.Get("position") != null); // Prints "true".
GD.Print(node.Get("other_property") != null); // Prints "false".
[/csharp]
[/codeblocks]
The [code]in[/code] operator will evaluate to [code]true[/code] as long as the key exists, even if the value is [code]null[/code].
Objects also receive notifications. Notifications are a simple way to notify the object about different events, so they can all be handled together. See [method _notification].
2021-06-04 16:03:15 +00:00
[b]Note:[/b] Unlike references to a [RefCounted], references to an Object stored in a variable can become invalid without warning. Therefore, it's recommended to use [RefCounted] for data classes instead of [Object].
[b]Note:[/b] The [code]script[/code] property is not exposed like most properties, but it does have a setter and getter ([code]set_script()[/code] and [code]get_script()[/code]).
</description>
<tutorials>
<link title="When and how to avoid using nodes for everything">$DOCS_URL/tutorials/best_practices/node_alternatives.html</link>
<link title="Object notifications">$DOCS_URL/tutorials/best_practices/godot_notifications.html</link>
</tutorials>
<methods>
<method name="_get" qualifiers="virtual">
<return type="Variant" />
<argument index="0" name="property" type="StringName" />
<description>
Virtual method which can be overridden to customize the return value of [method get].
2017-11-07 23:23:34 +00:00
Returns the given property. Returns [code]null[/code] if the [code]property[/code] does not exist.
</description>
</method>
<method name="_get_property_list" qualifiers="virtual">
<return type="Array" />
<description>
Virtual method which can be overridden to customize the return value of [method get_property_list].
Returns the object's property list as an [Array] of dictionaries.
Each property's [Dictionary] must contain at least [code]name: String[/code] and [code]type: int[/code] (see [enum Variant.Type]) entries. Optionally, it can also include [code]hint: int[/code] (see [enum PropertyHint]), [code]hint_string: String[/code], and [code]usage: int[/code] (see [enum PropertyUsageFlags]).
</description>
</method>
<method name="_init" qualifiers="virtual">
<return type="void" />
<description>
Called when the object is initialized in memory. Can be defined to take in parameters, that are passed in when constructing.
[b]Note:[/b] If [method _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 as [method PackedScene.instantiate]) is used, then initialization will fail.
</description>
</method>
<method name="_notification" qualifiers="virtual">
<return type="void" />
<argument index="0" name="what" type="int" />
<description>
Called whenever the object receives a notification, which is identified in [code]what[/code] by a constant. The base [Object] 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.
</description>
</method>
<method name="_set" qualifiers="virtual">
<return type="bool" />
<argument index="0" name="property" type="StringName" />
<argument index="1" name="value" type="Variant" />
<description>
Virtual method which can be overridden to customize the return value of [method set].
2017-11-07 23:23:34 +00:00
Sets a property. Returns [code]true[/code] if the [code]property[/code] exists.
</description>
</method>
<method name="_to_string" qualifiers="virtual">
<return type="String" />
<description>
Virtual method which can be overridden to customize the return value of [method to_string], and thus the object's representation where it is converted to a string, e.g. with [code]print(obj)[/code].
Returns a [String] representing the object. If not overridden, defaults to [code]"[ClassName:RID]"[/code].
</description>
</method>
<method name="add_user_signal">
<return type="void" />
<argument index="0" name="signal" type="String" />
<argument index="1" name="arguments" type="Array" default="[]" />
<description>
Adds a user-defined [code]signal[/code]. Arguments are optional, but can be added as an [Array] of dictionaries, each containing [code]name: String[/code] and [code]type: int[/code] (see [enum Variant.Type]) entries.
</description>
</method>
<method name="call" qualifiers="vararg">
<return type="Variant" />
<argument index="0" name="method" type="StringName" />
<description>
Calls the [code]method[/code] 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:
[codeblocks]
[gdscript]
var node = Node3D.new()
node.call("rotate", Vector3(1.0, 0.0, 0.0), 1.571)
[/gdscript]
[csharp]
var node = new Node3D();
node.Call("rotate", new Vector3(1f, 0f, 0f), 1.571f);
[/csharp]
[/codeblocks]
[b]Note:[/b] 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).
</description>
</method>
<method name="call_deferred" qualifiers="vararg">
<return type="Variant" />
<argument index="0" name="method" type="StringName" />
<description>
Calls the [code]method[/code] on the object during idle time. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example:
[codeblocks]
[gdscript]
var node = Node3D.new()
node.call_deferred("rotate", Vector3(1.0, 0.0, 0.0), 1.571)
[/gdscript]
[csharp]
var node = new Node3D();
node.CallDeferred("rotate", new Vector3(1f, 0f, 0f), 1.571f);
[/csharp]
[/codeblocks]
[b]Note:[/b] 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).
</description>
</method>
<method name="callv">
<return type="Variant" />
<argument index="0" name="method" type="StringName" />
<argument index="1" name="arg_array" type="Array" />
<description>
2019-08-08 06:51:18 +00:00
Calls the [code]method[/code] on the object and returns the result. Contrarily to [method call], this method does not support a variable number of arguments but expects all parameters to be via a single [Array].
[codeblocks]
[gdscript]
var node = Node3D.new()
node.callv("rotate", [Vector3(1.0, 0.0, 0.0), 1.571])
[/gdscript]
[csharp]
var node = new Node3D();
node.Callv("rotate", new Godot.Collections.Array { new Vector3(1f, 0f, 0f), 1.571f });
[/csharp]
[/codeblocks]
</description>
</method>
<method name="can_translate_messages" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if the object can translate strings. See [method set_message_translation] and [method tr].
</description>
</method>
<method name="connect">
<return type="int" enum="Error" />
<argument index="0" name="signal" type="StringName" />
<argument index="1" name="callable" type="Callable" />
<argument index="2" name="binds" type="Array" default="[]" />
<argument index="3" name="flags" type="int" default="0" />
<description>
Connects a [code]signal[/code] to a [code]callable[/code]. Pass optional [code]binds[/code] to the call as an [Array] of parameters. These parameters will be passed to the [Callable]'s method after any parameter used in the call to [method emit_signal]. Use [code]flags[/code] to set deferred or one-shot connections. See [enum ConnectFlags] constants.
2021-03-18 11:04:28 +00:00
[b]Note:[/b] This method is the legacy implementation for connecting signals. The recommended modern approach is to use [method Signal.connect] and to use [method Callable.bind] to add and validate parameter binds. Both syntaxes are shown below.
A signal can only be connected once to a [Callable]. It will print an error if already connected, unless the signal was connected with [constant CONNECT_REFERENCE_COUNTED]. To avoid this, first, use [method is_connected] to check for existing connections.
If the callable's target is destroyed in the game's lifecycle, the connection will be lost.
[b]Examples with recommended syntax:[/b]
Connecting signals is one of the most common operations in Godot and the API gives many options to do so, which are described further down. The code block below shows the recommended approach for both GDScript and C#.
[codeblocks]
[gdscript]
func _ready():
var button = Button.new()
# `button_down` here is a Signal object, and we thus call the Signal.connect() method,
# not Object.connect(). See discussion below for a more in-depth overview of the API.
button.button_down.connect(_on_button_down)
# This assumes that a `Player` class exists which defines a `hit` signal.
var player = Player.new()
# We use Signal.connect() again, and we also use the Callable.bind() method which
# returns a new Callable with the parameter binds.
player.hit.connect(_on_player_hit.bind("sword", 100))
func _on_button_down():
print("Button down!")
func _on_player_hit(weapon_type, damage):
print("Hit with weapon %s for %d damage." % [weapon_type, damage])
[/gdscript]
[csharp]
public override void _Ready()
{
var button = new Button();
// C# supports passing signals as events, so we can use this idiomatic construct:
button.ButtonDown += OnButtonDown;
// This assumes that a `Player` class exists which defines a `Hit` signal.
var player = new Player();
// Signals as events (`player.Hit += OnPlayerHit;`) do not support argument binding. You have to use:
player.Hit.Connect(OnPlayerHit, new Godot.Collections.Array {"sword", 100 });
}
private void OnButtonDown()
{
GD.Print("Button down!");
}
private void OnPlayerHit(string weaponType, int damage)
{
GD.Print(String.Format("Hit with weapon {0} for {1} damage.", weaponType, damage));
}
[/csharp]
[/codeblocks]
[b][code]Object.connect()[/code] or [code]Signal.connect()[/code]?[/b]
As seen above, the recommended method to connect signals is not [method Object.connect]. The code block below shows the four options for connecting signals, using either this legacy method or the recommended [method Signal.connect], and using either an implicit [Callable] or a manually defined one.
[codeblocks]
[gdscript]
func _ready():
var button = Button.new()
# Option 1: Object.connect() with an implicit Callable for the defined function.
button.connect("button_down", _on_button_down)
# Option 2: Object.connect() with a constructed Callable using a target object and method name.
button.connect("button_down", Callable(self, "_on_button_down"))
# Option 3: Signal.connect() with an implicit Callable for the defined function.
button.button_down.connect(_on_button_down)
# Option 4: Signal.connect() with a constructed Callable using a target object and method name.
button.button_down.connect(Callable(self, "_on_button_down"))
func _on_button_down():
print("Button down!")
[/gdscript]
[csharp]
public override void _Ready()
{
var button = new Button();
// Option 1: Object.Connect() with an implicit Callable for the defined function.
button.Connect("button_down", OnButtonDown);
// Option 2: Object.connect() with a constructed Callable using a target object and method name.
button.Connect("button_down", new Callable(self, nameof(OnButtonDown)));
// Option 3: Signal.connect() with an implicit Callable for the defined function.
button.ButtonDown.Connect(OnButtonDown);
// Option 3b: In C#, we can use signals as events and connect with this more idiomatic syntax:
button.ButtonDown += OnButtonDown;
// Option 4: Signal.connect() with a constructed Callable using a target object and method name.
button.ButtonDown.Connect(new Callable(self, nameof(OnButtonDown)));
}
private void OnButtonDown()
{
GD.Print("Button down!");
}
[/csharp]
[/codeblocks]
While all options have the same outcome ([code]button[/code]'s [signal BaseButton.button_down] signal will be connected to [code]_on_button_down[/code]), option 3 offers the best validation: it will print a compile-time error if either the [code]button_down[/code] signal or the [code]_on_button_down[/code] callable are undefined. On the other hand, option 2 only relies on string names and will only be able to validate either names at runtime: it will print a runtime error if [code]"button_down"[/code] doesn't correspond to a signal, or if [code]"_on_button_down"[/code] is not a registered method in the object [code]self[/code]. The main reason for using options 1, 2, or 4 would be if you actually need to use strings (e.g. to connect signals programmatically based on strings read from a configuration file). Otherwise, option 3 is the recommended (and fastest) method.
[b]Parameter bindings and passing:[/b]
For legacy or language-specific reasons, there are also several ways to bind parameters to signals. One can pass a [code]binds[/code] [Array] to [method Object.connect] or [method Signal.connect], or use the recommended [method Callable.bind] method to create a new callable from an existing one, with the given parameter binds.
One can also pass additional parameters when emitting the signal with [method emit_signal]. The examples below show the relationship between those two types of parameters.
[codeblocks]
[gdscript]
func _ready():
# This assumes that a `Player` class exists which defines a `hit` signal.
var player = Player.new()
# Option 1: Using Callable.bind().
player.hit.connect(_on_player_hit.bind("sword", 100))
# Option 2: Using a `binds` Array in Signal.connect() (same syntax for Object.connect()).
player.hit.connect(_on_player_hit, ["sword", 100])
# Parameters added when emitting the signal are passed first.
player.emit_signal("hit", "Dark lord", 5)
# Four arguments, since we pass two when emitting (hit_by, level)
# and two when connecting (weapon_type, damage).
func _on_player_hit(hit_by, level, weapon_type, damage):
print("Hit by %s (level %d) with weapon %s for %d damage." % [hit_by, level, weapon_type, damage])
[/gdscript]
[csharp]
public override void _Ready()
{
// This assumes that a `Player` class exists which defines a `Hit` signal.
var player = new Player();
// Option 1: Using Callable.Bind(). This way we can still use signals as events.
player.Hit += OnPlayerHit.Bind("sword", 100);
// Option 2: Using a `binds` Array in Signal.Connect() (same syntax for Object.Connect()).
player.Hit.Connect(OnPlayerHit, new Godot.Collections.Array{ "sword", 100 });
// Parameters added when emitting the signal are passed first.
player.EmitSignal("hit", "Dark lord", 5);
}
// Four arguments, since we pass two when emitting (hitBy, level)
// and two when connecting (weaponType, damage).
private void OnPlayerHit(string hitBy, int level, string weaponType, int damage)
{
GD.Print(String.Format("Hit by {0} (level {1}) with weapon {2} for {3} damage.", hitBy, level, weaponType, damage));
}
[/csharp]
[/codeblocks]
</description>
</method>
<method name="disconnect">
<return type="void" />
<argument index="0" name="signal" type="StringName" />
<argument index="1" name="callable" type="Callable" />
<description>
Disconnects a [code]signal[/code] from a given [code]callable[/code].
If you try to disconnect a connection that does not exist, the method will print an error. Use [method is_connected] to ensure that the connection exists.
</description>
</method>
<method name="emit_signal" qualifiers="vararg">
<return type="int" enum="Error" />
<argument index="0" name="signal" type="StringName" />
<description>
Emits the given [code]signal[/code]. 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:
[codeblocks]
[gdscript]
emit_signal("hit", "sword", 100)
emit_signal("game_over")
[/gdscript]
[csharp]
EmitSignal("hit", "sword", 100);
EmitSignal("game_over");
[/csharp]
[/codeblocks]
</description>
</method>
<method name="free">
<return type="void" />
<description>
Deletes the object from memory. Any pre-existing reference to the freed object will become invalid, e.g. [code]is_instance_valid(object)[/code] will return [code]false[/code].
</description>
</method>
<method name="get" qualifiers="const">
<return type="Variant" />
<argument index="0" name="property" type="StringName" />
<description>
Returns the [Variant] value of the given [code]property[/code]. If the [code]property[/code] doesn't exist, this will return [code]null[/code].
[b]Note:[/b] 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).
</description>
</method>
<method name="get_class" qualifiers="const">
<return type="String" />
<description>
Returns the object's class as a [String]. See also [method is_class].
[b]Note:[/b] [method get_class] does not take [code]class_name[/code] declarations into account. If the object has a [code]class_name[/code] defined, the base class name will be returned instead.
</description>
</method>
<method name="get_incoming_connections" qualifiers="const">
<return type="Array" />
<description>
2017-11-07 23:23:34 +00:00
Returns an [Array] of dictionaries with information about signals that are connected to the object.
Each [Dictionary] contains three String entries:
- [code]source[/code] is a reference to the signal emitter.
- [code]signal_name[/code] is the name of the connected signal.
- [code]method_name[/code] is the name of the method to which the signal is connected.
</description>
</method>
2017-11-24 08:16:27 +00:00
<method name="get_indexed" qualifiers="const">
<return type="Variant" />
<argument index="0" name="property" type="NodePath" />
2017-11-24 08:16:27 +00:00
<description>
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 ([code]:[/code]) to access nested properties. Examples: [code]"position:x"[/code] or [code]"material:next_pass:blend_mode"[/code].
[b]Note:[/b] Even though the method takes [NodePath] argument, it doesn't support actual paths to [Node]s in the scene tree, only colon-separated sub-property paths. For the purpose of nodes, use [method Node.get_node_and_resource] instead.
2017-11-24 08:16:27 +00:00
</description>
</method>
<method name="get_instance_id" qualifiers="const">
<return type="int" />
<description>
2017-11-07 23:23:34 +00:00
Returns the object's unique instance ID.
2021-01-04 13:33:44 +00:00
This ID can be saved in [EncodedObjectAsID], and can be used to retrieve the object instance with [method @GlobalScope.instance_from_id].
</description>
</method>
<method name="get_meta" qualifiers="const">
<return type="Variant" />
<argument index="0" name="name" type="StringName" />
<argument index="1" name="default" type="Variant" default="null" />
<description>
Returns the object's metadata entry for the given [code]name[/code].
Throws error if the entry does not exist, unless [code]default[/code] is not [code]null[/code] (in which case the default value will be returned).
</description>
</method>
<method name="get_meta_list" qualifiers="const">
<return type="PackedStringArray" />
<description>
Returns the object's metadata as a [PackedStringArray].
</description>
</method>
<method name="get_method_list" qualifiers="const">
<return type="Array" />
<description>
2017-11-07 23:23:34 +00:00
Returns the object's methods and their signatures as an [Array].
</description>
</method>
<method name="get_property_list" qualifiers="const">
<return type="Array" />
<description>
Returns the object's property list as an [Array] of dictionaries.
Each property's [Dictionary] contain at least [code]name: String[/code] and [code]type: int[/code] (see [enum Variant.Type]) entries. Optionally, it can also include [code]hint: int[/code] (see [enum PropertyHint]), [code]hint_string: String[/code], and [code]usage: int[/code] (see [enum PropertyUsageFlags]).
</description>
</method>
<method name="get_script" qualifiers="const">
<return type="Variant" />
<description>
Returns the object's [Script] instance, or [code]null[/code] if none is assigned.
</description>
</method>
<method name="get_signal_connection_list" qualifiers="const">
<return type="Array" />
<argument index="0" name="signal" type="StringName" />
<description>
2017-11-07 23:23:34 +00:00
Returns an [Array] of connections for the given [code]signal[/code].
</description>
</method>
<method name="get_signal_list" qualifiers="const">
<return type="Array" />
<description>
2017-11-07 23:23:34 +00:00
Returns the list of signals as an [Array] of dictionaries.
</description>
</method>
<method name="has_meta" qualifiers="const">
<return type="bool" />
<argument index="0" name="name" type="StringName" />
<description>
Returns [code]true[/code] if a metadata entry is found with the given [code]name[/code].
</description>
</method>
<method name="has_method" qualifiers="const">
<return type="bool" />
<argument index="0" name="method" type="StringName" />
<description>
2017-11-07 23:23:34 +00:00
Returns [code]true[/code] if the object contains the given [code]method[/code].
</description>
</method>
2019-11-10 05:59:44 +00:00
<method name="has_signal" qualifiers="const">
<return type="bool" />
<argument index="0" name="signal" type="StringName" />
2019-11-10 05:59:44 +00:00
<description>
Returns [code]true[/code] if the given [code]signal[/code] exists.
</description>
</method>
<method name="has_user_signal" qualifiers="const">
<return type="bool" />
<argument index="0" name="signal" type="StringName" />
<description>
2019-11-10 05:59:44 +00:00
Returns [code]true[/code] if the given user-defined [code]signal[/code] exists. Only signals added using [method add_user_signal] are taken into account.
</description>
</method>
<method name="is_blocking_signals" qualifiers="const">
<return type="bool" />
<description>
2017-11-07 23:23:34 +00:00
Returns [code]true[/code] if signal emission blocking is enabled.
</description>
</method>
<method name="is_class" qualifiers="const">
<return type="bool" />
<argument index="0" name="class" type="String" />
<description>
Returns [code]true[/code] if the object inherits from the given [code]class[/code]. See also [method get_class].
[b]Note:[/b] [method is_class] does not take [code]class_name[/code] declarations into account. If the object has a [code]class_name[/code] defined, [method is_class] will return [code]false[/code] for that name.
</description>
</method>
<method name="is_connected" qualifiers="const">
<return type="bool" />
<argument index="0" name="signal" type="StringName" />
<argument index="1" name="callable" type="Callable" />
<description>
Returns [code]true[/code] if a connection exists for a given [code]signal[/code] and [code]callable[/code].
</description>
</method>
<method name="is_queued_for_deletion" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if the [method Node.queue_free] method was called for the object.
</description>
</method>
<method name="notification">
<return type="void" />
<argument index="0" name="what" type="int" />
<argument index="1" name="reversed" type="bool" default="false" />
<description>
Send a given notification to the object, which will also trigger a call to the [method _notification] method of all classes that the object inherits from.
If [code]reversed[/code] is [code]true[/code], [method _notification] is called first on the object's own class, and then up to its successive parent classes. If [code]reversed[/code] is [code]false[/code], [method _notification] is called first on the highest ancestor ([Object] itself), and then down to its successive inheriting classes.
</description>
</method>
<method name="notify_property_list_changed">
<return type="void" />
<description>
Notify the editor that the property list has changed by emitting the [signal property_list_changed] signal, so that editor plugins can take the new values into account.
</description>
</method>
2019-04-30 12:23:59 +00:00
<method name="remove_meta">
<return type="void" />
<argument index="0" name="name" type="StringName" />
2019-04-30 12:23:59 +00:00
<description>
Removes a given entry from the object's metadata. See also [method set_meta].
2019-04-30 12:23:59 +00:00
</description>
</method>
<method name="set">
<return type="void" />
<argument index="0" name="property" type="StringName" />
<argument index="1" name="value" type="Variant" />
<description>
Assigns a new value to the given property. If the [code]property[/code] does not exist or the given value's type doesn't match, nothing will happen.
[b]Note:[/b] 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).
</description>
</method>
<method name="set_block_signals">
<return type="void" />
<argument index="0" name="enable" type="bool" />
<description>
2019-04-17 11:42:56 +00:00
If set to [code]true[/code], signal emission is blocked.
</description>
</method>
2018-11-20 08:34:45 +00:00
<method name="set_deferred">
<return type="void" />
<argument index="0" name="property" type="StringName" />
<argument index="1" name="value" type="Variant" />
2018-11-20 08:34:45 +00:00
<description>
Assigns a new value to the given property, after the current frame's physics step. This is equivalent to calling [method set] via [method call_deferred], i.e. [code]call_deferred("set", property, value)[/code].
[b]Note:[/b] 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).
2018-11-20 08:34:45 +00:00
</description>
</method>
2017-11-24 08:16:27 +00:00
<method name="set_indexed">
<return type="void" />
<argument index="0" name="property" type="NodePath" />
<argument index="1" name="value" type="Variant" />
2017-11-24 08:16:27 +00:00
<description>
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 ([code]:[/code]) to access nested properties. Example:
[codeblocks]
[gdscript]
var node = Node2D.new()
node.set_indexed("position", Vector2(42, 0))
node.set_indexed("position:y", -10)
print(node.position) # (42, -10)
[/gdscript]
[csharp]
var node = new Node2D();
node.SetIndexed("position", new Vector2(42, 0));
node.SetIndexed("position:y", -10);
GD.Print(node.Position); // (42, -10)
[/csharp]
[/codeblocks]
2017-11-24 08:16:27 +00:00
</description>
</method>
<method name="set_message_translation">
<return type="void" />
<argument index="0" name="enable" type="bool" />
<description>
Defines whether the object can translate strings (with calls to [method tr]). Enabled by default.
</description>
</method>
<method name="set_meta">
<return type="void" />
<argument index="0" name="name" type="StringName" />
<argument index="1" name="value" type="Variant" />
<description>
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 [method remove_meta]. Metadata is also removed if its value is set to [code]null[/code]. This means you can also use [code]set_meta("name", null)[/code] to remove metadata for [code]"name"[/code].
</description>
</method>
<method name="set_script">
<return type="void" />
<argument index="0" name="script" type="Variant" />
<description>
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 _init] method will be called.
</description>
</method>
2019-05-21 11:26:37 +00:00
<method name="to_string">
<return type="String" />
2019-05-21 11:26:37 +00:00
<description>
Returns a [String] representing the object. If not overridden, defaults to [code]"[ClassName:RID]"[/code].
2019-05-21 11:26:37 +00:00
Override the method [method _to_string] to customize the [String] representation.
</description>
</method>
<method name="tr" qualifiers="const">
<return type="String" />
<argument index="0" name="message" type="StringName" />
<argument index="1" name="context" type="StringName" default="&quot;&quot;" />
<description>
Translates a message using translation catalogs configured in the Project Settings. An additional context could be used to specify the translation context.
Only works if message translation is enabled (which it is by default), otherwise it returns the [code]message[/code] unchanged. See [method set_message_translation].
See [url=$DOCS_URL/tutorials/i18n/internationalizing_games.html]Internationalizing games[/url] for examples of the usage of this method.
</description>
</method>
<method name="tr_n" qualifiers="const">
<return type="String" />
<argument index="0" name="message" type="StringName" />
<argument index="1" name="plural_message" type="StringName" />
<argument index="2" name="n" type="int" />
<argument index="3" name="context" type="StringName" default="&quot;&quot;" />
<description>
Translates a message involving plurals using translation catalogs configured in the Project Settings. An additional context could be used to specify the translation context.
Only works if message translation is enabled (which it is by default), otherwise it returns the [code]message[/code] or [code]plural_message[/code] unchanged. See [method set_message_translation].
The number [code]n[/code] is the number or quantity of the plural object. It will be used to guide the translation system to fetch the correct plural form for the selected language.
[b]Note:[/b] Negative and floating-point values usually represent physical entities for which singular and plural don't clearly apply. In such cases, use [method tr].
See [url=$DOCS_URL/tutorials/i18n/localization_using_gettext.html]Localization using gettext[/url] for examples of the usage of this method.
</description>
</method>
</methods>
<signals>
<signal name="property_list_changed">
<description>
</description>
</signal>
<signal name="script_changed">
<description>
Emitted whenever the object's script is changed.
</description>
</signal>
</signals>
<constants>
2017-11-24 22:16:30 +00:00
<constant name="NOTIFICATION_POSTINITIALIZE" value="0">
Called right when the object is initialized. Not available in script.
</constant>
2017-11-24 22:16:30 +00:00
<constant name="NOTIFICATION_PREDELETE" value="1">
Called before the object is about to be deleted.
</constant>
2017-11-24 22:16:30 +00:00
<constant name="CONNECT_DEFERRED" value="1" enum="ConnectFlags">
Connects a signal in deferred mode. This way, signal emissions are stored in a queue, then set on idle time.
</constant>
2017-11-24 22:16:30 +00:00
<constant name="CONNECT_PERSIST" value="2" enum="ConnectFlags">
Persisting connections are saved when the object is serialized to file.
</constant>
2017-11-24 22:16:30 +00:00
<constant name="CONNECT_ONESHOT" value="4" enum="ConnectFlags">
One-shot connections disconnect themselves after emission.
</constant>
2018-08-20 22:35:30 +00:00
<constant name="CONNECT_REFERENCE_COUNTED" value="8" enum="ConnectFlags">
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.
2018-08-20 22:35:30 +00:00
</constant>
</constants>
</class>