Debian Codegraph @

doc/classes/Object.xml

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <class name="Object" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3 <brief_description>
4 Base class for all other classes in the engine.
5 </brief_description>
6 <description>
7 An advanced [Variant] type. All classes in the engine inherit from Object. Each class may define new properties, methods or signals, which are available to all inheriting classes. For example, a [Sprite2D] instance is able to call [method Node.add_child] because it inherits from [Node].
8 You can create new instances, using [code]Object.new()[/code] in GDScript, or [code]new GodotObject[/code] in C#.
9 To delete an Object instance, call [method free]. This is necessary for most classes inheriting Object, because they do not manage memory on their own, and will otherwise cause memory leaks when no longer in use. There are a few classes that perform memory management. For example, [RefCounted] (and by extension [Resource]) deletes itself when no longer referenced, and [Node] deletes its children when freed.
10 Objects can have a [Script] attached to them. Once the [Script] is instantiated, it effectively acts as an extension to the base class, allowing it to define and inherit new properties, methods and signals.
11 Inside a [Script], [method _get_property_list] may be overridden to customize properties in several ways. This allows them to be available to the editor, display as lists of options, sub-divide into groups, save on disk, etc. Scripting languages offer easier ways to customize properties, such as with the [annotation @GDScript.@export] annotation.
12 Godot is very dynamic. An object's script, and therefore its properties, methods and signals, can be changed at run-time. Because of this, there can be occasions where, for example, a property required by a method may not exist. To prevent run-time errors, see methods such as [method set], [method get], [method call], [method has_method], [method has_signal], etc. Note that these methods are [b]much[/b] slower than direct references.
13 In GDScript, you can also check if a given property, method, or signal name exists in an object with the [code]in[/code] operator:
14 [codeblock]
15 var node = Node.new()
16 print("name" in node) # Prints true
17 print("get_parent" in node) # Prints true
18 print("tree_entered" in node) # Prints true
19 print("unknown" in node) # Prints false
20 [/codeblock]
21 Notifications are [int] constants commonly sent and received by objects. For example, on every rendered frame, the [SceneTree] notifies nodes inside the tree with a [constant Node.NOTIFICATION_PROCESS]. The nodes receive it and may call [method Node._process] to update. To make use of notifications, see [method notification] and [method _notification].
22 Lastly, every object can also contain metadata (data about data). [method set_meta] can be useful to store information that the object itself does not depend on. To keep your code clean, making excessive use of metadata is discouraged.
23 [b]Note:[/b] Unlike references to a [RefCounted], references to an object stored in a variable can become invalid without being set to [code]null[/code]. To check if an object has been deleted, do [i]not[/i] compare it against [code]null[/code]. Instead, use [method @GlobalScope.is_instance_valid]. It's also recommended to inherit from [RefCounted] for classes storing data instead of [Object].
24 [b]Note:[/b] The [code]script[/code] is not exposed like most properties. To set or get an object's [Script] in code, use [method set_script] and [method get_script], respectively.
25 [b]Note:[/b] In a boolean context, an [Object] will evaluate to [code]false[/code] if it is equal to [code]null[/code] or it has been freed. Otherwise, an [Object] will always evaluate to [code]true[/code]. See also [method @GlobalScope.is_instance_valid].
26 </description>
27 <tutorials>
28 <link title="Object class introduction">$DOCS_URL/engine_details/architecture/object_class.html</link>
29 <link title="When and how to avoid using nodes for everything">$DOCS_URL/tutorials/best_practices/node_alternatives.html</link>
30 <link title="Object notifications">$DOCS_URL/tutorials/best_practices/godot_notifications.html</link>
31 </tutorials>
32 <methods>
33 <method name="_get" qualifiers="virtual">
34 <return type="Variant" />
35 <param index="0" name="property" type="StringName" />
36 <description>
37 Override this method to customize the behavior of [method get]. Should return the given [param property]'s value, or [code]null[/code] if the [param property] should be handled normally.
38 Combined with [method _set] and [method _get_property_list], this method allows defining custom properties, which is particularly useful for editor plugins.
39 [b]Note:[/b] This method is not called when getting built-in properties of an object, including properties defined with [annotation @GDScript.@export].
40 [codeblocks]
41 [gdscript]
42 func _get(property):
43 if property == "fake_property":
44 print("Getting my property!")
45 return 4
46
47 func _get_property_list():
48 return [
49 { "name": "fake_property", "type": TYPE_INT }
50 ]
51 [/gdscript]
52 [csharp]
53 public override Variant _Get(StringName property)
54 {
55 if (property == "FakeProperty")
56 {
57 GD.Print("Getting my property!");
58 return 4;
59 }
60 return default;
61 }
62
63 public override Godot.Collections.Array&lt;Godot.Collections.Dictionary&gt; _GetPropertyList()
64 {
65 return
66 [
67 new Godot.Collections.Dictionary()
68 {
69 { "name", "FakeProperty" },
70 { "type", (int)Variant.Type.Int },
71 },
72 ];
73 }
74 [/csharp]
75 [/codeblocks]
76 [b]Note:[/b] Unlike other virtual methods, this method is called automatically for every script that overrides it. This means that the base implementation should not be called via [code]super[/code] in GDScript or its equivalents in other languages. The bottom-most sub-class will be called first, with subsequent calls ascending the class hierarchy. The call chain will stop on the first class that returns a non-[code]null[/code] value.
77 </description>
78 </method>
79 <method name="_get_property_list" qualifiers="virtual">
80 <return type="Dictionary[]" />
81 <description>
82 Override this method to provide a custom list of additional properties to handle by the engine.
83 Should return a property list, as an [Array] of dictionaries. The result is added to the array of [method get_property_list], and should be formatted in the same way. Each [Dictionary] must at least contain the [code]name[/code] and [code]type[/code] entries.
84 You can use [method _property_can_revert] and [method _property_get_revert] to customize the default values of the properties added by this method.
85 The example below displays a list of numbers shown as words going from [code]ZERO[/code] to [code]FIVE[/code], with [code]number_count[/code] controlling the size of the list:
86 [codeblocks]
87 [gdscript]
88 @tool
89 extends Node
90
91 @export var number_count = 3:
92 set(nc):
93 number_count = nc
94 numbers.resize(number_count)
95 notify_property_list_changed()
96
97 var numbers = PackedInt32Array([0, 0, 0])
98
99 func _get_property_list():
100 var properties = []
101
102 for i in range(number_count):
103 properties.append({
104 "name": "number_%d" % i,
105 "type": TYPE_INT,
106 "hint": PROPERTY_HINT_ENUM,
107 "hint_string": "ZERO,ONE,TWO,THREE,FOUR,FIVE",
108 })
109
110 return properties
111
112 func _get(property):
113 if property.begins_with("number_"):
114 var index = property.get_slice("_", 1).to_int()
115 return numbers[index]
116
117 func _set(property, value):
118 if property.begins_with("number_"):
119 var index = property.get_slice("_", 1).to_int()
120 numbers[index] = value
121 return true
122 return false
123 [/gdscript]
124 [csharp]
125 [Tool]
126 public partial class MyNode : Node
127 {
128 private int _numberCount;
129
130 [Export]
131 public int NumberCount
132 {
133 get =&gt; _numberCount;
134 set
135 {
136 _numberCount = value;
137 _numbers.Resize(_numberCount);
138 NotifyPropertyListChanged();
139 }
140 }
141
142 private Godot.Collections.Array&lt;int&gt; _numbers = [];
143
144 public override Godot.Collections.Array&lt;Godot.Collections.Dictionary&gt; _GetPropertyList()
145 {
146 Godot.Collections.Array&lt;Godot.Collections.Dictionary&gt; properties = [];
147
148 for (int i = 0; i &lt; _numberCount; i++)
149 {
150 properties.Add(new Godot.Collections.Dictionary()
151 {
152 { "name", $"number_{i}" },
153 { "type", (int)Variant.Type.Int },
154 { "hint", (int)PropertyHint.Enum },
155 { "hint_string", "Zero,One,Two,Three,Four,Five" },
156 });
157 }
158
159 return properties;
160 }
161
162 public override Variant _Get(StringName property)
163 {
164 string propertyName = property.ToString();
165 if (propertyName.StartsWith("number_"))
166 {
167 int index = int.Parse(propertyName.Substring("number_".Length));
168 return _numbers[index];
169 }
170 return default;
171 }
172
173 public override bool _Set(StringName property, Variant value)
174 {
175 string propertyName = property.ToString();
176 if (propertyName.StartsWith("number_"))
177 {
178 int index = int.Parse(propertyName.Substring("number_".Length));
179 _numbers[index] = value.As&lt;int&gt;();
180 return true;
181 }
182 return false;
183 }
184 }
185 [/csharp]
186 [/codeblocks]
187 [b]Note:[/b] This method is intended for advanced purposes. For most common use cases, the scripting languages offer easier ways to handle properties. See [annotation @GDScript.@export], [annotation @GDScript.@export_enum], [annotation @GDScript.@export_group], etc. If you want to customize exported properties, use [method _validate_property].
188 [b]Note:[/b] If the object's script is not [annotation @GDScript.@tool], this method will not be called in the editor.
189 [b]Note:[/b] Unlike other virtual methods, this method is called automatically for every script that overrides it. This means that the base implementation should not be called via [code]super[/code] in GDScript or its equivalents in other languages. The bottom-most sub-class will be called first, with subsequent calls ascending the class hierarchy.
190 </description>
191 </method>
192 <method name="_init" qualifiers="virtual">
193 <return type="void" />
194 <description>
195 Called when the object's script is instantiated, oftentimes after the object is initialized in memory (through [code]Object.new()[/code] in GDScript, or [code]new GodotObject[/code] in C#). It can be also defined to take in parameters. This method is similar to a constructor in most programming languages.
196 [b]Note:[/b] If [method _init] is defined with [i]required[/i] parameters, the Object with script may only be created directly. If any other means (such as [method PackedScene.instantiate] or [method Node.duplicate]) are used, the script's initialization will fail.
197 </description>
198 </method>
199 <method name="_iter_get" qualifiers="virtual">
200 <return type="Variant" />
201 <param index="0" name="iter" type="Variant" />
202 <description>
203 Returns the current iterable value. [param iter] stores the iteration state, but unlike [method _iter_init] and [method _iter_next] the state is supposed to be read-only, so there is no [Array] wrapper.
204 [b]Tip:[/b] In GDScript, you can use a subtype of [Variant] as the return type for [method _iter_get]. The specified type will be used to set the type of the iterator variable in [code]for[/code] loops, enhancing type safety.
205 </description>
206 </method>
207 <method name="_iter_init" qualifiers="virtual">
208 <return type="bool" />
209 <param index="0" name="iter" type="Array" />
210 <description>
211 Initializes the iterator. [param iter] stores the iteration state. Since GDScript does not support passing arguments by reference, a single-element array is used as a wrapper. Returns [code]true[/code] so long as the iterator has not reached the end.
212 [codeblock]
213 class MyRange:
214 var _from
215 var _to
216
217 func _init(from, to):
218 assert(from &lt;= to)
219 _from = from
220 _to = to
221
222 func _iter_init(iter):
223 iter[0] = _from
224 return iter[0] &lt; _to
225
226 func _iter_next(iter):
227 iter[0] += 1
228 return iter[0] &lt; _to
229
230 func _iter_get(iter):
231 return iter
232
233 func _ready():
234 var my_range = MyRange.new(2, 5)
235 for x in my_range:
236 print(x) # Prints 2, 3, 4.
237 [/codeblock]
238 [b]Note:[/b] Alternatively, you can ignore [param iter] and use the object's state instead, see [url=$DOCS_URL/tutorials/scripting/gdscript/gdscript_advanced.html#custom-iterators]online docs[/url] for an example. Note that in this case you will not be able to reuse the same iterator instance in nested loops. Also, make sure you reset the iterator state in this method if you want to reuse the same instance multiple times.
239 </description>
240 </method>
241 <method name="_iter_next" qualifiers="virtual">
242 <return type="bool" />
243 <param index="0" name="iter" type="Array" />
244 <description>
245 Moves the iterator to the next iteration. [param iter] stores the iteration state. Since GDScript does not support passing arguments by reference, a single-element array is used as a wrapper. Returns [code]true[/code] so long as the iterator has not reached the end.
246 </description>
247 </method>
248 <method name="_notification" qualifiers="virtual">
249 <return type="void" />
250 <param index="0" name="what" type="int" />
251 <description>
252 Called when the object receives a notification, which can be identified in [param what] by comparing it with a constant. See also [method notification].
253 [codeblocks]
254 [gdscript]
255 func _notification(what):
256 if what == NOTIFICATION_PREDELETE:
257 print("Goodbye!")
258 [/gdscript]
259 [csharp]
260 public override void _Notification(int what)
261 {
262 if (what == NotificationPredelete)
263 {
264 GD.Print("Goodbye!");
265 }
266 }
267 [/csharp]
268 [/codeblocks]
269 [b]Note:[/b] The base [Object] defines a few notifications ([constant NOTIFICATION_POSTINITIALIZE] and [constant NOTIFICATION_PREDELETE]). Inheriting classes such as [Node] define a lot more notifications, which are also received by this method.
270 [b]Note:[/b] Unlike other virtual methods, this method is called automatically for every script that overrides it. This means that the base implementation should not be called via [code]super[/code] in GDScript or its equivalents in other languages. Call order depends on the [code]reversed[/code] argument of [method notification] and varies between different notifications. Most notifications are sent in the forward order (i.e. Object class first, most derived class last).
271 </description>
272 </method>
273 <method name="_property_can_revert" qualifiers="virtual">
274 <return type="bool" />
275 <param index="0" name="property" type="StringName" />
276 <description>
277 Override this method to customize the given [param property]'s revert behavior. Should return [code]true[/code] if the [param property] has a custom default value and is revertible in the Inspector dock. Use [method _property_get_revert] to specify the [param property]'s default value.
278 [b]Note:[/b] This method must return consistently, regardless of the current value of the [param property].
279 [b]Note:[/b] Unlike other virtual methods, this method is called automatically for every script that overrides it. This means that the base implementation should not be called via [code]super[/code] in GDScript or its equivalents in other languages. The bottom-most sub-class will be called first, with subsequent calls ascending the class hierarchy. The call chain will stop on the first class that returns [code]true[/code].
280 </description>
281 </method>
282 <method name="_property_get_revert" qualifiers="virtual">
283 <return type="Variant" />
284 <param index="0" name="property" type="StringName" />
285 <description>
286 Override this method to customize the given [param property]'s revert behavior. Should return the default value for the [param property]. If the default value differs from the [param property]'s current value, a revert icon is displayed in the Inspector dock.
287 [b]Note:[/b] [method _property_can_revert] must also be overridden for this method to be called.
288 [b]Note:[/b] Unlike other virtual methods, this method is called automatically for every script that overrides it. This means that the base implementation should not be called via [code]super[/code] in GDScript or its equivalents in other languages. The bottom-most sub-class will be called first, with subsequent calls ascending the class hierarchy. The call chain will stop on the first class that returns a non-[code]null[/code] value.
289 </description>
290 </method>
291 <method name="_set" qualifiers="virtual">
292 <return type="bool" />
293 <param index="0" name="property" type="StringName" />
294 <param index="1" name="value" type="Variant" />
295 <description>
296 Override this method to customize the behavior of [method set]. Should set the [param property] to [param value] and return [code]true[/code], or [code]false[/code] if the [param property] should be handled normally. The [i]exact[/i] way to set the [param property] is up to this method's implementation.
297 Combined with [method _get] and [method _get_property_list], this method allows defining custom properties, which is particularly useful for editor plugins.
298 [b]Note:[/b] This method is not called when setting built-in properties of an object, including properties defined with [annotation @GDScript.@export].
299 [codeblocks]
300 [gdscript]
301 var internal_data = {}
302
303 func _set(property, value):
304 if property == "fake_property":
305 # Storing the value in the fake property.
306 internal_data["fake_property"] = value
307 return true
308 return false
309
310 func _get_property_list():
311 return [
312 { "name": "fake_property", "type": TYPE_INT }
313 ]
314 [/gdscript]
315 [csharp]
316 private Godot.Collections.Dictionary _internalData = new Godot.Collections.Dictionary();
317
318 public override bool _Set(StringName property, Variant value)
319 {
320 if (property == "FakeProperty")
321 {
322 // Storing the value in the fake property.
323 _internalData["FakeProperty"] = value;
324 return true;
325 }
326
327 return false;
328 }
329
330 public override Godot.Collections.Array&lt;Godot.Collections.Dictionary&gt; _GetPropertyList()
331 {
332 return
333 [
334 new Godot.Collections.Dictionary()
335 {
336 { "name", "FakeProperty" },
337 { "type", (int)Variant.Type.Int },
338 },
339 ];
340 }
341 [/csharp]
342 [/codeblocks]
343 [b]Note:[/b] Unlike other virtual methods, this method is called automatically for every script that overrides it. This means that the base implementation should not be called via [code]super[/code] in GDScript or its equivalents in other languages. The bottom-most sub-class will be called first, with subsequent calls ascending the class hierarchy. The call chain will stop on the first class that returns [code]true[/code].
344 </description>
345 </method>
346 <method name="_to_string" qualifiers="virtual">
347 <return type="String" />
348 <description>
349 Override this method to customize the return value of [method to_string], and therefore the object's representation as a [String].
350 [codeblock]
351 func _to_string():
352 return "Welcome to Godot 4!"
353
354 func _init():
355 print(self) # Prints "Welcome to Godot 4!"
356 var a = str(self) # a is "Welcome to Godot 4!"
357 [/codeblock]
358 </description>
359 </method>
360 <method name="_validate_property" qualifiers="virtual">
361 <return type="void" />
362 <param index="0" name="property" type="Dictionary" />
363 <description>
364 Override this method to customize existing properties. Every property info goes through this method, except properties added with [method _get_property_list]. The dictionary contents is the same as in [method _get_property_list].
365 [codeblocks]
366 [gdscript]
367 @tool
368 extends Node
369
370 @export var is_number_editable: bool:
371 set(value):
372 is_number_editable = value
373 notify_property_list_changed()
374 @export var number: int
375
376 func _validate_property(property: Dictionary):
377 if property.name == "number" and not is_number_editable:
378 property.usage |= PROPERTY_USAGE_READ_ONLY
379 [/gdscript]
380 [csharp]
381 [Tool]
382 public partial class MyNode : Node
383 {
384 private bool _isNumberEditable;
385
386 [Export]
387 public bool IsNumberEditable
388 {
389 get =&gt; _isNumberEditable;
390 set
391 {
392 _isNumberEditable = value;
393 NotifyPropertyListChanged();
394 }
395 }
396
397 [Export]
398 public int Number { get; set; }
399
400 public override void _ValidateProperty(Godot.Collections.Dictionary property)
401 {
402 if (property["name"].AsStringName() == PropertyName.Number &amp;&amp; !IsNumberEditable)
403 {
404 var usage = property["usage"].As&lt;PropertyUsageFlags&gt;() | PropertyUsageFlags.ReadOnly;
405 property["usage"] = (int)usage;
406 }
407 }
408 }
409 [/csharp]
410 [/codeblocks]
411 </description>
412 </method>
413 <method name="add_user_signal">
414 <return type="void" />
415 <param index="0" name="signal" type="String" />
416 <param index="1" name="arguments" type="Array" default="[]" />
417 <description>
418 Adds a user-defined signal named [param signal]. Optional arguments for the signal can be added as an [Array] of dictionaries, each defining a [code]name[/code] [String] and a [code]type[/code] [int] (see [enum Variant.Type]). See also [method has_user_signal] and [method remove_user_signal].
419 [codeblocks]
420 [gdscript]
421 add_user_signal("hurt", [
422 { "name": "damage", "type": TYPE_INT },
423 { "name": "source", "type": TYPE_OBJECT }
424 ])
425 [/gdscript]
426 [csharp]
427 AddUserSignal("Hurt",
428 [
429 new Godot.Collections.Dictionary()
430 {
431 { "name", "damage" },
432 { "type", (int)Variant.Type.Int },
433 },
434 new Godot.Collections.Dictionary()
435 {
436 { "name", "source" },
437 { "type", (int)Variant.Type.Object },
438 },
439 ]);
440 [/csharp]
441 [/codeblocks]
442 </description>
443 </method>
444 <method name="call" qualifiers="vararg">
445 <return type="Variant" />
446 <param index="0" name="method" type="StringName" />
447 <description>
448 Calls the [param method] on the object and returns the result. This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
449 [codeblocks]
450 [gdscript]
451 var node = Node3D.new()
452 node.call("rotate", Vector3(1.0, 0.0, 0.0), 1.571)
453 [/gdscript]
454 [csharp]
455 var node = new Node3D();
456 node.Call(Node3D.MethodName.Rotate, new Vector3(1f, 0f, 0f), 1.571f);
457 [/csharp]
458 [/codeblocks]
459 [b]Note:[/b] In C#, [param method] must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the [code]MethodName[/code] class to avoid allocating a new [StringName] on each call.
460 </description>
461 </method>
462 <method name="call_deferred" qualifiers="vararg">
463 <return type="Variant" />
464 <param index="0" name="method" type="StringName" />
465 <description>
466 Calls the [param method] on the object during idle time. Always returns [code]null[/code], [b]not[/b] the method's result.
467 Idle time happens mainly at the end of process and physics frames. In it, deferred calls will be run until there are none left, which means you can defer calls from other deferred calls and they'll still be run in the current idle time cycle. This means you should not call a method deferred from itself (or from a method called by it), as this causes infinite recursion the same way as if you had called the method directly.
468 This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
469 [codeblocks]
470 [gdscript]
471 var node = Node3D.new()
472 node.call_deferred("rotate", Vector3(1.0, 0.0, 0.0), 1.571)
473 [/gdscript]
474 [csharp]
475 var node = new Node3D();
476 node.CallDeferred(Node3D.MethodName.Rotate, new Vector3(1f, 0f, 0f), 1.571f);
477 [/csharp]
478 [/codeblocks]
479 For methods that are deferred from the same thread, the order of execution at idle time is identical to the order in which [code skip-lint]call_deferred[/code] was called.
480 See also [method Callable.call_deferred].
481 [b]Note:[/b] In C#, [param method] must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the [code]MethodName[/code] class to avoid allocating a new [StringName] on each call.
482 [b]Note:[/b] If you're looking to delay the function call by a frame, refer to the [signal SceneTree.process_frame] and [signal SceneTree.physics_frame] signals.
483 [codeblock]
484 var node = Node3D.new()
485 # Make a Callable and bind the arguments to the node's rotate() call.
486 var callable = node.rotate.bind(Vector3(1.0, 0.0, 0.0), 1.571)
487 # Connect the callable to the process_frame signal, so it gets called in the next process frame.
488 # CONNECT_ONE_SHOT makes sure it only gets called once instead of every frame.
489 get_tree().process_frame.connect(callable, CONNECT_ONE_SHOT)
490 [/codeblock]
491 </description>
492 </method>
493 <method name="callv">
494 <return type="Variant" />
495 <param index="0" name="method" type="StringName" />
496 <param index="1" name="arg_array" type="Array" />
497 <description>
498 Calls the [param method] on the object and returns the result. Unlike [method call], this method expects all parameters to be contained inside [param arg_array].
499 [codeblocks]
500 [gdscript]
501 var node = Node3D.new()
502 node.callv("rotate", [Vector3(1.0, 0.0, 0.0), 1.571])
503 [/gdscript]
504 [csharp]
505 var node = new Node3D();
506 node.Callv(Node3D.MethodName.Rotate, [new Vector3(1f, 0f, 0f), 1.571f]);
507 [/csharp]
508 [/codeblocks]
509 [b]Note:[/b] In C#, [param method] must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the [code]MethodName[/code] class to avoid allocating a new [StringName] on each call.
510 </description>
511 </method>
512 <method name="can_translate_messages" qualifiers="const">
513 <return type="bool" />
514 <description>
515 Returns [code]true[/code] if the object is allowed to translate messages with [method tr] and [method tr_n]. See also [method set_message_translation].
516 </description>
517 </method>
518 <method name="cancel_free">
519 <return type="void" />
520 <description>
521 If this method is called during [constant NOTIFICATION_PREDELETE], this object will reject being freed and will remain allocated. This is mostly an internal function used for error handling to avoid the user from freeing objects when they are not intended to.
522 </description>
523 </method>
524 <method name="connect">
525 <return type="int" enum="Error" />
526 <param index="0" name="signal" type="StringName" />
527 <param index="1" name="callable" type="Callable" />
528 <param index="2" name="flags" type="int" default="0" />
529 <description>
530 Connects a [param signal] by name to a [param callable]. Optional [param flags] can be also added to configure the connection's behavior (see [enum ConnectFlags] constants).
531 A signal can only be connected once to the same [Callable]. If the signal is already connected, this method returns [constant ERR_INVALID_PARAMETER] and generates an error, unless the signal is connected with [constant CONNECT_REFERENCE_COUNTED]. To prevent this, use [method is_connected] first to check for existing connections.
532 [b]Note:[/b] If the [param callable]'s object is freed, the connection will be lost.
533 [b]Note:[/b] In GDScript, it is generally recommended to connect signals with [method Signal.connect] instead.
534 [b]Note:[/b] This method, and all other signal-related methods, are thread-safe.
535 </description>
536 </method>
537 <method name="disconnect">
538 <return type="void" />
539 <param index="0" name="signal" type="StringName" />
540 <param index="1" name="callable" type="Callable" />
541 <description>
542 Disconnects a [param signal] by name from a given [param callable]. If the connection does not exist, generates an error. Use [method is_connected] to make sure that the connection exists.
543 </description>
544 </method>
545 <method name="emit_signal" qualifiers="vararg">
546 <return type="int" enum="Error" />
547 <param index="0" name="signal" type="StringName" />
548 <description>
549 Emits the given [param signal] by name. The signal must exist, so it should be a built-in signal of this class or one of its inherited classes, or a user-defined signal (see [method add_user_signal]). This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
550 Returns [constant ERR_UNAVAILABLE] if [param signal] does not exist or the parameters are invalid.
551 [codeblocks]
552 [gdscript]
553 emit_signal("hit", "sword", 100)
554 emit_signal("game_over")
555 [/gdscript]
556 [csharp]
557 EmitSignal(SignalName.Hit, "sword", 100);
558 EmitSignal(SignalName.GameOver);
559 [/csharp]
560 [/codeblocks]
561 [b]Note:[/b] In C#, [param signal] must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the [code]SignalName[/code] class to avoid allocating a new [StringName] on each call.
562 </description>
563 </method>
564 <method name="free" keywords="delete, remove, kill, die">
565 <return type="void" />
566 <description>
567 Deletes the object from memory. Pre-existing references to the object become invalid, and any attempt to access them will result in a runtime error. Checking the references with [method @GlobalScope.is_instance_valid] will return [code]false[/code]. This is equivalent to the [code]memdelete[/code] function in GDExtension C++.
568 </description>
569 </method>
570 <method name="get" qualifiers="const">
571 <return type="Variant" />
572 <param index="0" name="property" type="StringName" />
573 <description>
574 Returns the [Variant] value of the given [param property]. If the [param property] does not exist, this method returns [code]null[/code].
575 [codeblocks]
576 [gdscript]
577 var node = Node2D.new()
578 node.rotation = 1.5
579 var a = node.get("rotation") # a is 1.5
580 [/gdscript]
581 [csharp]
582 var node = new Node2D();
583 node.Rotation = 1.5f;
584 var a = node.Get(Node2D.PropertyName.Rotation); // a is 1.5
585 [/csharp]
586 [/codeblocks]
587 [b]Note:[/b] In C#, [param property] must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the [code]PropertyName[/code] class to avoid allocating a new [StringName] on each call.
588 </description>
589 </method>
590 <method name="get_class" qualifiers="const">
591 <return type="String" />
592 <description>
593 Returns the object's built-in class name, as a [String]. See also [method is_class].
594 [b]Note:[/b] This method ignores [code]class_name[/code] declarations. If this object's script has defined a [code]class_name[/code], the base, built-in class name is returned instead.
595 </description>
596 </method>
597 <method name="get_incoming_connections" qualifiers="const">
598 <return type="Dictionary[]" />
599 <description>
600 Returns an [Array] of signal connections received by this object. Each connection is represented as a [Dictionary] that contains three entries:
601 - [code]signal[/code] is a reference to the [Signal];
602 - [code]callable[/code] is a reference to the [Callable];
603 - [code]flags[/code] is a combination of [enum ConnectFlags].
604 </description>
605 </method>
606 <method name="get_indexed" qualifiers="const">
607 <return type="Variant" />
608 <param index="0" name="property_path" type="NodePath" />
609 <description>
610 Gets the object's property indexed by the given [param property_path]. The path should be a [NodePath] relative to the current object and can use the colon character ([code]:[/code]) to access nested properties.
611 [b]Examples:[/b] [code]"position:x"[/code] or [code]"material:next_pass:blend_mode"[/code].
612 [codeblocks]
613 [gdscript]
614 var node = Node2D.new()
615 node.position = Vector2(5, -10)
616 var a = node.get_indexed("position") # a is Vector2(5, -10)
617 var b = node.get_indexed("position:y") # b is -10
618 [/gdscript]
619 [csharp]
620 var node = new Node2D();
621 node.Position = new Vector2(5, -10);
622 var a = node.GetIndexed("position"); // a is Vector2(5, -10)
623 var b = node.GetIndexed("position:y"); // b is -10
624 [/csharp]
625 [/codeblocks]
626 [b]Note:[/b] In C#, [param property_path] must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the [code]PropertyName[/code] class to avoid allocating a new [StringName] on each call.
627 [b]Note:[/b] This method does not support actual paths to nodes in the [SceneTree], only sub-property paths. In the context of nodes, use [method Node.get_node_and_resource] instead.
628 </description>
629 </method>
630 <method name="get_instance_id" qualifiers="const">
631 <return type="int" />
632 <description>
633 Returns the object's unique instance ID. This ID can be saved in [EncodedObjectAsID], and can be used to retrieve this object instance with [method @GlobalScope.instance_from_id].
634 [b]Note:[/b] This ID is only useful during the current session. It won't correspond to a similar object if the ID is sent over a network, or loaded from a file at a later time.
635 </description>
636 </method>
637 <method name="get_meta" qualifiers="const">
638 <return type="Variant" />
639 <param index="0" name="name" type="StringName" />
640 <param index="1" name="default" type="Variant" default="null" />
641 <description>
642 Returns the object's metadata value for the given entry [param name]. If the entry does not exist, returns [param default]. If [param default] is [code]null[/code], an error is also generated.
643 [b]Note:[/b] A metadata's name must be a valid identifier as per [method StringName.is_valid_identifier] method.
644 [b]Note:[/b] Metadata that has a name starting with an underscore ([code]_[/code]) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
645 </description>
646 </method>
647 <method name="get_meta_list" qualifiers="const">
648 <return type="StringName[]" />
649 <description>
650 Returns the object's metadata entry names as an [Array] of [StringName]s.
651 </description>
652 </method>
653 <method name="get_method_argument_count" qualifiers="const">
654 <return type="int" />
655 <param index="0" name="method" type="StringName" />
656 <description>
657 Returns the number of arguments of the given [param method] by name.
658 [b]Note:[/b] In C#, [param method] must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the [code]MethodName[/code] class to avoid allocating a new [StringName] on each call.
659 </description>
660 </method>
661 <method name="get_method_list" qualifiers="const">
662 <return type="Dictionary[]" />
663 <description>
664 Returns this object's methods and their signatures as an [Array] of dictionaries. Each [Dictionary] contains the following entries:
665 - [code]name[/code] is the name of the method, as a [String];
666 - [code]args[/code] is an [Array] of dictionaries representing the arguments;
667 - [code]default_args[/code] is the default arguments as an [Array] of variants;
668 - [code]flags[/code] is a combination of [enum MethodFlags];
669 - [code]id[/code] is the method's internal identifier [int];
670 - [code]return[/code] is the returned value, as a [Dictionary];
671 [b]Note:[/b] The dictionaries of [code]args[/code] and [code]return[/code] are formatted identically to the results of [method get_property_list], although not all entries are used.
672 </description>
673 </method>
674 <method name="get_property_list" qualifiers="const">
675 <return type="Dictionary[]" />
676 <description>
677 Returns the object's property list as an [Array] of dictionaries. Each [Dictionary] contains the following entries:
678 - [code]name[/code] is the property's name, as a [String];
679 - [code]class_name[/code] is an empty [StringName], unless the property is [constant TYPE_OBJECT] and it inherits from a class;
680 - [code]type[/code] is the property's type, as an [int] (see [enum Variant.Type]);
681 - [code]hint[/code] is [i]how[/i] the property is meant to be edited (see [enum PropertyHint]);
682 - [code]hint_string[/code] depends on the hint (see [enum PropertyHint]);
683 - [code]usage[/code] is a combination of [enum PropertyUsageFlags].
684 [b]Note:[/b] In GDScript, all class members are treated as properties. In C# and GDExtension, it may be necessary to explicitly mark class members as Godot properties using decorators or attributes.
685 </description>
686 </method>
687 <method name="get_script" qualifiers="const">
688 <return type="Variant" />
689 <description>
690 Returns the object's [Script] instance, or [code]null[/code] if no script is attached.
691 </description>
692 </method>
693 <method name="get_signal_connection_list" qualifiers="const">
694 <return type="Dictionary[]" />
695 <param index="0" name="signal" type="StringName" />
696 <description>
697 Returns an [Array] of connections for the given [param signal] name. Each connection is represented as a [Dictionary] that contains three entries:
698 - [code skip-lint]signal[/code] is a reference to the [Signal];
699 - [code]callable[/code] is a reference to the connected [Callable];
700 - [code]flags[/code] is a combination of [enum ConnectFlags].
701 </description>
702 </method>
703 <method name="get_signal_list" qualifiers="const">
704 <return type="Dictionary[]" />
705 <description>
706 Returns the list of existing signals as an [Array] of dictionaries.
707 [b]Note:[/b] Due to the implementation, each [Dictionary] is formatted very similarly to the returned values of [method get_method_list].
708 </description>
709 </method>
710 <method name="get_translation_domain" qualifiers="const">
711 <return type="StringName" />
712 <description>
713 Returns the name of the translation domain used by [method tr] and [method tr_n]. See also [TranslationServer].
714 </description>
715 </method>
716 <method name="has_connections" qualifiers="const">
717 <return type="bool" />
718 <param index="0" name="signal" type="StringName" />
719 <description>
720 Returns [code]true[/code] if any connection exists on the given [param signal] name.
721 [b]Note:[/b] In C#, [param signal] must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the [code]SignalName[/code] class to avoid allocating a new [StringName] on each call.
722 </description>
723 </method>
724 <method name="has_meta" qualifiers="const">
725 <return type="bool" />
726 <param index="0" name="name" type="StringName" />
727 <description>
728 Returns [code]true[/code] if a metadata entry is found with the given [param name]. See also [method get_meta], [method set_meta] and [method remove_meta].
729 [b]Note:[/b] A metadata's name must be a valid identifier as per [method StringName.is_valid_identifier] method.
730 [b]Note:[/b] Metadata that has a name starting with an underscore ([code]_[/code]) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
731 </description>
732 </method>
733 <method name="has_method" qualifiers="const">
734 <return type="bool" />
735 <param index="0" name="method" type="StringName" />
736 <description>
737 Returns [code]true[/code] if the given [param method] name exists in the object.
738 [b]Note:[/b] In C#, [param method] must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the [code]MethodName[/code] class to avoid allocating a new [StringName] on each call.
739 </description>
740 </method>
741 <method name="has_signal" qualifiers="const">
742 <return type="bool" />
743 <param index="0" name="signal" type="StringName" />
744 <description>
745 Returns [code]true[/code] if the given [param signal] name exists in the object.
746 [b]Note:[/b] In C#, [param signal] must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the [code]SignalName[/code] class to avoid allocating a new [StringName] on each call.
747 </description>
748 </method>
749 <method name="has_user_signal" qualifiers="const">
750 <return type="bool" />
751 <param index="0" name="signal" type="StringName" />
752 <description>
753 Returns [code]true[/code] if the given user-defined [param signal] name exists. Only signals added with [method add_user_signal] are included. See also [method remove_user_signal].
754 </description>
755 </method>
756 <method name="is_blocking_signals" qualifiers="const">
757 <return type="bool" />
758 <description>
759 Returns [code]true[/code] if the object is blocking its signals from being emitted. See [method set_block_signals].
760 </description>
761 </method>
762 <method name="is_class" qualifiers="const">
763 <return type="bool" />
764 <param index="0" name="class" type="String" />
765 <description>
766 Returns [code]true[/code] if the object inherits from the given [param class]. See also [method get_class].
767 [codeblocks]
768 [gdscript]
769 var sprite2d = Sprite2D.new()
770 sprite2d.is_class("Sprite2D") # Returns true
771 sprite2d.is_class("Node") # Returns true
772 sprite2d.is_class("Node3D") # Returns false
773 [/gdscript]
774 [csharp]
775 var sprite2D = new Sprite2D();
776 sprite2D.IsClass("Sprite2D"); // Returns true
777 sprite2D.IsClass("Node"); // Returns true
778 sprite2D.IsClass("Node3D"); // Returns false
779 [/csharp]
780 [/codeblocks]
781 [b]Note:[/b] This method ignores [code]class_name[/code] declarations in the object's script.
782 </description>
783 </method>
784 <method name="is_connected" qualifiers="const">
785 <return type="bool" />
786 <param index="0" name="signal" type="StringName" />
787 <param index="1" name="callable" type="Callable" />
788 <description>
789 Returns [code]true[/code] if a connection exists between the given [param signal] name and [param callable].
790 [b]Note:[/b] In C#, [param signal] must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the [code]SignalName[/code] class to avoid allocating a new [StringName] on each call.
791 </description>
792 </method>
793 <method name="is_queued_for_deletion" qualifiers="const">
794 <return type="bool" />
795 <description>
796 Returns [code]true[/code] if the [method Node.queue_free] method was called for the object.
797 </description>
798 </method>
799 <method name="notification">
800 <return type="void" />
801 <param index="0" name="what" type="int" />
802 <param index="1" name="reversed" type="bool" default="false" />
803 <description>
804 Sends the given [param what] notification to all classes inherited by the object, triggering calls to [method _notification], starting from the highest ancestor (the [Object] class) and going down to the object's script.
805 If [param reversed] is [code]true[/code], the call order is reversed.
806 [codeblocks]
807 [gdscript]
808 var player = Node2D.new()
809 player.set_script(load("res://player.gd"))
810
811 player.notification(NOTIFICATION_ENTER_TREE)
812 # The call order is Object -&gt; Node -&gt; Node2D -&gt; player.gd.
813
814 player.notification(NOTIFICATION_ENTER_TREE, true)
815 # The call order is player.gd -&gt; Node2D -&gt; Node -&gt; Object.
816 [/gdscript]
817 [csharp]
818 var player = new Node2D();
819 player.SetScript(GD.Load("res://player.gd"));
820
821 player.Notification(NotificationEnterTree);
822 // The call order is GodotObject -&gt; Node -&gt; Node2D -&gt; player.gd.
823
824 player.Notification(NotificationEnterTree, true);
825 // The call order is player.gd -&gt; Node2D -&gt; Node -&gt; GodotObject.
826 [/csharp]
827 [/codeblocks]
828 </description>
829 </method>
830 <method name="notify_property_list_changed">
831 <return type="void" />
832 <description>
833 Emits the [signal property_list_changed] signal. This is mainly used to refresh the editor, so that the Inspector and editor plugins are properly updated.
834 </description>
835 </method>
836 <method name="property_can_revert" qualifiers="const">
837 <return type="bool" />
838 <param index="0" name="property" type="StringName" />
839 <description>
840 Returns [code]true[/code] if the given [param property] has a custom default value. Use [method property_get_revert] to get the [param property]'s default value.
841 [b]Note:[/b] This method is used by the Inspector dock to display a revert icon. The object must implement [method _property_can_revert] to customize the default value. If [method _property_can_revert] is not implemented, this method returns [code]false[/code].
842 </description>
843 </method>
844 <method name="property_get_revert" qualifiers="const">
845 <return type="Variant" />
846 <param index="0" name="property" type="StringName" />
847 <description>
848 Returns the custom default value of the given [param property]. Use [method property_can_revert] to check if the [param property] has a custom default value.
849 [b]Note:[/b] This method is used by the Inspector dock to display a revert icon. The object must implement [method _property_get_revert] to customize the default value. If [method _property_get_revert] is not implemented, this method returns [code]null[/code].
850 </description>
851 </method>
852 <method name="remove_meta">
853 <return type="void" />
854 <param index="0" name="name" type="StringName" />
855 <description>
856 Removes the given entry [param name] from the object's metadata. See also [method has_meta], [method get_meta] and [method set_meta].
857 [b]Note:[/b] A metadata's name must be a valid identifier as per [method StringName.is_valid_identifier] method.
858 [b]Note:[/b] Metadata that has a name starting with an underscore ([code]_[/code]) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
859 </description>
860 </method>
861 <method name="remove_user_signal">
862 <return type="void" />
863 <param index="0" name="signal" type="StringName" />
864 <description>
865 Removes the given user signal [param signal] from the object. See also [method add_user_signal] and [method has_user_signal].
866 </description>
867 </method>
868 <method name="set">
869 <return type="void" />
870 <param index="0" name="property" type="StringName" />
871 <param index="1" name="value" type="Variant" />
872 <description>
873 Assigns [param value] to the given [param property]. If the property does not exist or the given [param value]'s type doesn't match, nothing happens.
874 [codeblocks]
875 [gdscript]
876 var node = Node2D.new()
877 node.set("global_scale", Vector2(8, 2.5))
878 print(node.global_scale) # Prints (8.0, 2.5)
879 [/gdscript]
880 [csharp]
881 var node = new Node2D();
882 node.Set(Node2D.PropertyName.GlobalScale, new Vector2(8, 2.5f));
883 GD.Print(node.GlobalScale); // Prints (8, 2.5)
884 [/csharp]
885 [/codeblocks]
886 [b]Note:[/b] In C#, [param property] must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the [code]PropertyName[/code] class to avoid allocating a new [StringName] on each call.
887 </description>
888 </method>
889 <method name="set_block_signals">
890 <return type="void" />
891 <param index="0" name="enable" type="bool" />
892 <description>
893 If set to [code]true[/code], the object becomes unable to emit signals. As such, [method emit_signal] and signal connections will not work, until it is set to [code]false[/code].
894 </description>
895 </method>
896 <method name="set_deferred">
897 <return type="void" />
898 <param index="0" name="property" type="StringName" />
899 <param index="1" name="value" type="Variant" />
900 <description>
901 Assigns [param value] to the given [param property], at the end of the current frame. This is equivalent to calling [method set] through [method call_deferred].
902 [codeblocks]
903 [gdscript]
904 var node = Node2D.new()
905 add_child(node)
906
907 node.rotation = 1.5
908 node.set_deferred("rotation", 3.0)
909 print(node.rotation) # Prints 1.5
910
911 await get_tree().process_frame
912 print(node.rotation) # Prints 3.0
913 [/gdscript]
914 [csharp]
915 var node = new Node2D();
916 node.Rotation = 1.5f;
917 node.SetDeferred(Node2D.PropertyName.Rotation, 3f);
918 GD.Print(node.Rotation); // Prints 1.5
919
920 await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
921 GD.Print(node.Rotation); // Prints 3.0
922 [/csharp]
923 [/codeblocks]
924 [b]Note:[/b] In C#, [param property] must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the [code]PropertyName[/code] class to avoid allocating a new [StringName] on each call.
925 </description>
926 </method>
927 <method name="set_indexed">
928 <return type="void" />
929 <param index="0" name="property_path" type="NodePath" />
930 <param index="1" name="value" type="Variant" />
931 <description>
932 Assigns a new [param value] to the property identified by the [param property_path]. The path should be a [NodePath] relative to this object, and can use the colon character ([code]:[/code]) to access nested properties.
933 [codeblocks]
934 [gdscript]
935 var node = Node2D.new()
936 node.set_indexed("position", Vector2(42, 0))
937 node.set_indexed("position:y", -10)
938 print(node.position) # Prints (42.0, -10.0)
939 [/gdscript]
940 [csharp]
941 var node = new Node2D();
942 node.SetIndexed("position", new Vector2(42, 0));
943 node.SetIndexed("position:y", -10);
944 GD.Print(node.Position); // Prints (42, -10)
945 [/csharp]
946 [/codeblocks]
947 [b]Note:[/b] In C#, [param property_path] must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the [code]PropertyName[/code] class to avoid allocating a new [StringName] on each call.
948 </description>
949 </method>
950 <method name="set_message_translation">
951 <return type="void" />
952 <param index="0" name="enable" type="bool" />
953 <description>
954 If set to [code]true[/code], allows the object to translate messages with [method tr] and [method tr_n]. Enabled by default. See also [method can_translate_messages].
955 </description>
956 </method>
957 <method name="set_meta">
958 <return type="void" />
959 <param index="0" name="name" type="StringName" />
960 <param index="1" name="value" type="Variant" />
961 <description>
962 Adds or changes the entry [param name] inside the object's metadata. The metadata [param value] can be any [Variant], although some types cannot be serialized correctly.
963 If [param value] is [code]null[/code], the entry is removed. This is the equivalent of using [method remove_meta]. See also [method has_meta] and [method get_meta].
964 [b]Note:[/b] A metadata's name must be a valid identifier as per [method StringName.is_valid_identifier] method.
965 [b]Note:[/b] Metadata that has a name starting with an underscore ([code]_[/code]) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
966 </description>
967 </method>
968 <method name="set_script">
969 <return type="void" />
970 <param index="0" name="script" type="Variant" />
971 <description>
972 Attaches [param script] to the object, and instantiates it. As a result, the script's [method _init] is called. A [Script] is used to extend the object's functionality.
973 If a script already exists, its instance is detached, and its property values and state are lost. Built-in property values are still kept.
974 </description>
975 </method>
976 <method name="set_translation_domain">
977 <return type="void" />
978 <param index="0" name="domain" type="StringName" />
979 <description>
980 Sets the name of the translation domain used by [method tr] and [method tr_n]. See also [TranslationServer].
981 </description>
982 </method>
983 <method name="to_string">
984 <return type="String" />
985 <description>
986 Returns a [String] representing the object. Defaults to [code]"&lt;ClassName#RID&gt;"[/code]. Override [method _to_string] to customize the string representation of the object.
987 </description>
988 </method>
989 <method name="tr" qualifiers="const">
990 <return type="String" />
991 <param index="0" name="message" type="StringName" />
992 <param index="1" name="context" type="StringName" default="&amp;&quot;&quot;" />
993 <description>
994 Translates a [param message], using the translation catalogs configured in the Project Settings. Further [param context] can be specified to help with the translation. Note that most [Control] nodes automatically translate their strings, so this method is mostly useful for formatted strings or custom drawn text.
995 If [method can_translate_messages] is [code]false[/code], or no translation is available, this method returns the [param message] without changes. See [method set_message_translation].
996 For detailed examples, see [url=$DOCS_URL/tutorials/i18n/internationalizing_games.html]Internationalizing games[/url].
997 [b]Note:[/b] This method can't be used without an [Object] instance, as it requires the [method can_translate_messages] method. To translate strings in a static context, use [method TranslationServer.translate].
998 </description>
999 </method>
1000 <method name="tr_n" qualifiers="const">
1001 <return type="String" />
1002 <param index="0" name="message" type="StringName" />
1003 <param index="1" name="plural_message" type="StringName" />
1004 <param index="2" name="n" type="int" />
1005 <param index="3" name="context" type="StringName" default="&amp;&quot;&quot;" />
1006 <description>
1007 Translates a [param message] or [param plural_message], using the translation catalogs configured in the Project Settings. Further [param context] can be specified to help with the translation.
1008 If [method can_translate_messages] is [code]false[/code], or no translation is available, this method returns [param message] or [param plural_message], without changes. See [method set_message_translation].
1009 The [param n] is the number, or amount, of the message's subject. It is used by the translation system to fetch the correct plural form for the current language.
1010 For detailed examples, see [url=$DOCS_URL/tutorials/i18n/localization_using_gettext.html]Localization using gettext[/url].
1011 [b]Note:[/b] Negative and [float] numbers may not properly apply to some countable subjects. It's recommended to handle these cases with [method tr].
1012 [b]Note:[/b] This method can't be used without an [Object] instance, as it requires the [method can_translate_messages] method. To translate strings in a static context, use [method TranslationServer.translate_plural].
1013 </description>
1014 </method>
1015 </methods>
1016 <signals>
1017 <signal name="property_list_changed">
1018 <description>
1019 Emitted when [method notify_property_list_changed] is called.
1020 </description>
1021 </signal>
1022 <signal name="script_changed">
1023 <description>
1024 Emitted when the object's script is changed.
1025 [b]Note:[/b] When this signal is emitted, the new script is not initialized yet. If you need to access the new script, defer connections to this signal with [constant CONNECT_DEFERRED].
1026 </description>
1027 </signal>
1028 </signals>
1029 <constants>
1030 <constant name="NOTIFICATION_POSTINITIALIZE" value="0">
1031 Notification received when the object is initialized, before its script is attached. Used internally.
1032 </constant>
1033 <constant name="NOTIFICATION_PREDELETE" value="1">
1034 Notification received when the object is about to be deleted. Can be used like destructors in object-oriented programming languages.
1035 This notification is sent in reversed order.
1036 </constant>
1037 <constant name="NOTIFICATION_EXTENSION_RELOADED" value="2">
1038 Notification received when the object finishes hot reloading. This notification is only sent for extensions classes and derived.
1039 </constant>
1040 <constant name="CONNECT_DEFERRED" value="1" enum="ConnectFlags">
1041 Deferred connections trigger their [Callable]s on idle time (at the end of the frame), rather than instantly.
1042 </constant>
1043 <constant name="CONNECT_PERSIST" value="2" enum="ConnectFlags">
1044 Persisting connections are stored when the object is serialized (such as when using [method PackedScene.pack]). In the editor, connections created through the Signals dock are always persisting.
1045 [b]Note:[/b] Connections to lambda functions (that is, when the function code is embedded in the [method connect] call) cannot be made persistent.
1046 </constant>
1047 <constant name="CONNECT_ONE_SHOT" value="4" enum="ConnectFlags">
1048 One-shot connections disconnect themselves after emission.
1049 </constant>
1050 <constant name="CONNECT_REFERENCE_COUNTED" value="8" enum="ConnectFlags">
1051 Reference-counted connections can be assigned to the same [Callable] multiple times. Each disconnection decreases the internal counter. The signal fully disconnects only when the counter reaches 0.
1052 </constant>
1053 <constant name="CONNECT_APPEND_SOURCE_OBJECT" value="16" enum="ConnectFlags">
1054 On signal emission, the source object is automatically appended after the original arguments of the signal, regardless of the connected [Callable]'s unbinds which affect only the original arguments of the signal (see [method Callable.unbind], [method Callable.get_unbound_arguments_count]).
1055 [codeblock]
1056 extends Object
1057
1058 signal test_signal
1059
1060 func test():
1061 print(self) # Prints e.g. &lt;Object#35332818393&gt;
1062 test_signal.connect(prints.unbind(1), CONNECT_APPEND_SOURCE_OBJECT)
1063 test_signal.emit("emit_arg_1", "emit_arg_2") # Prints emit_arg_1 &lt;Object#35332818393&gt;
1064 [/codeblock]
1065 </constant>
1066 </constants>
1067 </class>