Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/gdscript/doc_classes/@GDScript.xml
10278 views
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<class name="@GDScript" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
3
<brief_description>
4
Built-in GDScript constants, functions, and annotations.
5
</brief_description>
6
<description>
7
A list of utility functions and annotations accessible from any script written in GDScript.
8
For the list of global functions and constants that can be accessed in any scripting language, see [@GlobalScope].
9
</description>
10
<tutorials>
11
<link title="GDScript exports">$DOCS_URL/tutorials/scripting/gdscript/gdscript_exports.html</link>
12
</tutorials>
13
<methods>
14
<method name="Color8" deprecated="Use [method Color.from_rgba8] instead.">
15
<return type="Color" />
16
<param index="0" name="r8" type="int" />
17
<param index="1" name="g8" type="int" />
18
<param index="2" name="b8" type="int" />
19
<param index="3" name="a8" type="int" default="255" />
20
<description>
21
Returns a [Color] constructed from red ([param r8]), green ([param g8]), blue ([param b8]), and optionally alpha ([param a8]) integer channels, each divided by [code]255.0[/code] for their final value. Using [method Color8] instead of the standard [Color] constructor is useful when you need to match exact color values in an [Image].
22
[codeblock]
23
var red = Color8(255, 0, 0) # Same as Color(1, 0, 0).
24
var dark_blue = Color8(0, 0, 51) # Same as Color(0, 0, 0.2).
25
var my_color = Color8(306, 255, 0, 102) # Same as Color(1.2, 1, 0, 0.4).
26
[/codeblock]
27
[b]Note:[/b] Due to the lower precision of [method Color8] compared to the standard [Color] constructor, a color created with [method Color8] will generally not be equal to the same color created with the standard [Color] constructor. Use [method Color.is_equal_approx] for comparisons to avoid issues with floating-point precision error.
28
</description>
29
</method>
30
<method name="assert">
31
<return type="void" />
32
<param index="0" name="condition" type="bool" />
33
<param index="1" name="message" type="String" default="&quot;&quot;" />
34
<description>
35
Asserts that the [param condition] is [code]true[/code]. If the [param condition] is [code]false[/code], an error is generated. When running from the editor, the running project will also be paused until you resume it. This can be used as a stronger form of [method @GlobalScope.push_error] for reporting errors to project developers or add-on users.
36
An optional [param message] can be shown in addition to the generic "Assertion failed" message. You can use this to provide additional details about why the assertion failed.
37
[b]Warning:[/b] For performance reasons, the code inside [method assert] is only executed in debug builds or when running the project from the editor. Don't include code that has side effects in an [method assert] call. Otherwise, the project will behave differently when exported in release mode.
38
[codeblock]
39
# Imagine we always want speed to be between 0 and 20.
40
var speed = -10
41
assert(speed &lt; 20) # True, the program will continue.
42
assert(speed &gt;= 0) # False, the program will stop.
43
assert(speed &gt;= 0 and speed &lt; 20) # You can also combine the two conditional statements in one check.
44
assert(speed &lt; 20, "the speed limit is 20") # Show a message.
45
[/codeblock]
46
[b]Note:[/b] [method assert] is a keyword, not a function. So you cannot access it as a [Callable] or use it inside expressions.
47
</description>
48
</method>
49
<method name="char">
50
<return type="String" />
51
<param index="0" name="code" type="int" />
52
<description>
53
Returns a single character (as a [String] of length 1) of the given Unicode code point [param code].
54
[codeblock]
55
print(char(65)) # Prints "A"
56
print(char(129302)) # Prints "🤖" (robot face emoji)
57
[/codeblock]
58
This is the inverse of [method ord]. See also [method String.chr] and [method String.unicode_at].
59
</description>
60
</method>
61
<method name="convert" deprecated="Use [method @GlobalScope.type_convert] instead.">
62
<return type="Variant" />
63
<param index="0" name="what" type="Variant" />
64
<param index="1" name="type" type="int" enum="Variant.Type" />
65
<description>
66
Converts [param what] to [param type] in the best way possible. The [param type] uses the [enum Variant.Type] values.
67
[codeblock]
68
var a = [4, 2.5, 1.2]
69
print(a is Array) # Prints true
70
71
var b = convert(a, TYPE_PACKED_BYTE_ARRAY)
72
print(b) # Prints [4, 2, 1]
73
print(b is Array) # Prints false
74
[/codeblock]
75
</description>
76
</method>
77
<method name="dict_to_inst" deprecated="Consider using [method JSON.to_native] or [method Object.get_property_list] instead.">
78
<return type="Object" />
79
<param index="0" name="dictionary" type="Dictionary" />
80
<description>
81
Converts a [param dictionary] (created with [method inst_to_dict]) back to an Object instance. Can be useful for deserializing.
82
</description>
83
</method>
84
<method name="get_stack">
85
<return type="Array" />
86
<description>
87
Returns an array of dictionaries representing the current call stack.
88
[codeblock]
89
func _ready():
90
foo()
91
92
func foo():
93
bar()
94
95
func bar():
96
print(get_stack())
97
[/codeblock]
98
Starting from [code]_ready()[/code], [code]bar()[/code] would print:
99
[codeblock lang=text]
100
[{function:bar, line:12, source:res://script.gd}, {function:foo, line:9, source:res://script.gd}, {function:_ready, line:6, source:res://script.gd}]
101
[/codeblock]
102
See also [method print_debug], [method print_stack], and [method Engine.capture_script_backtraces].
103
[b]Note:[/b] By default, backtraces are only available in editor builds and debug builds. To enable them for release builds as well, you need to enable [member ProjectSettings.debug/settings/gdscript/always_track_call_stacks].
104
</description>
105
</method>
106
<method name="inst_to_dict" deprecated="Consider using [method JSON.from_native] or [method Object.get_property_list] instead.">
107
<return type="Dictionary" />
108
<param index="0" name="instance" type="Object" />
109
<description>
110
Returns the passed [param instance] converted to a [Dictionary]. Can be useful for serializing.
111
[codeblock]
112
var foo = "bar"
113
func _ready():
114
var d = inst_to_dict(self)
115
print(d.keys())
116
print(d.values())
117
[/codeblock]
118
Prints out:
119
[codeblock lang=text]
120
[@subpath, @path, foo]
121
[, res://test.gd, bar]
122
[/codeblock]
123
[b]Note:[/b] This function can only be used to serialize objects with an attached [GDScript] stored in a separate file. Objects without an attached script, with a script written in another language, or with a built-in script are not supported.
124
[b]Note:[/b] This function is not recursive, which means that nested objects will not be represented as dictionaries. Also, properties passed by reference ([Object], [Dictionary], [Array], and packed arrays) are copied by reference, not duplicated.
125
</description>
126
</method>
127
<method name="is_instance_of">
128
<return type="bool" />
129
<param index="0" name="value" type="Variant" />
130
<param index="1" name="type" type="Variant" />
131
<description>
132
Returns [code]true[/code] if [param value] is an instance of [param type]. The [param type] value must be one of the following:
133
- A constant from the [enum Variant.Type] enumeration, for example [constant TYPE_INT].
134
- An [Object]-derived class which exists in [ClassDB], for example [Node].
135
- A [Script] (you can use any class, including inner one).
136
Unlike the right operand of the [code]is[/code] operator, [param type] can be a non-constant value. The [code]is[/code] operator supports more features (such as typed arrays). Use the operator instead of this method if you do not need to check the type dynamically.
137
[b]Examples:[/b]
138
[codeblock]
139
print(is_instance_of(a, TYPE_INT))
140
print(is_instance_of(a, Node))
141
print(is_instance_of(a, MyClass))
142
print(is_instance_of(a, MyClass.InnerClass))
143
[/codeblock]
144
[b]Note:[/b] If [param value] and/or [param type] are freed objects (see [method @GlobalScope.is_instance_valid]), or [param type] is not one of the above options, this method will raise a runtime error.
145
See also [method @GlobalScope.typeof], [method type_exists], [method Array.is_same_typed] (and other [Array] methods).
146
</description>
147
</method>
148
<method name="len">
149
<return type="int" />
150
<param index="0" name="var" type="Variant" />
151
<description>
152
Returns the length of the given Variant [param var]. The length can be the character count of a [String] or [StringName], the element count of any array type, or the size of a [Dictionary]. For every other Variant type, a run-time error is generated and execution is stopped.
153
[codeblock]
154
var a = [1, 2, 3, 4]
155
len(a) # Returns 4
156
157
var b = "Hello!"
158
len(b) # Returns 6
159
[/codeblock]
160
</description>
161
</method>
162
<method name="load">
163
<return type="Resource" />
164
<param index="0" name="path" type="String" />
165
<description>
166
Returns a [Resource] from the filesystem located at the absolute [param path]. Unless it's already referenced elsewhere (such as in another script or in the scene), the resource is loaded from disk on function call, which might cause a slight delay, especially when loading large scenes. To avoid unnecessary delays when loading something multiple times, either store the resource in a variable or use [method preload]. This method is equivalent of using [method ResourceLoader.load] with [constant ResourceLoader.CACHE_MODE_REUSE].
167
[b]Note:[/b] Resource paths can be obtained by right-clicking on a resource in the FileSystem dock and choosing "Copy Path", or by dragging the file from the FileSystem dock into the current script.
168
[codeblock]
169
# Load a scene called "main" located in the root of the project directory and cache it in a variable.
170
var main = load("res://main.tscn") # main will contain a PackedScene resource.
171
[/codeblock]
172
[b]Important:[/b] Relative paths are [i]not[/i] relative to the script calling this method, instead it is prefixed with [code]"res://"[/code]. Loading from relative paths might not work as expected.
173
This function is a simplified version of [method ResourceLoader.load], which can be used for more advanced scenarios.
174
[b]Note:[/b] Files have to be imported into the engine first to load them using this function. If you want to load [Image]s at run-time, you may use [method Image.load]. If you want to import audio files, you can use the snippet described in [member AudioStreamMP3.data].
175
[b]Note:[/b] If [member ProjectSettings.editor/export/convert_text_resources_to_binary] is [code]true[/code], [method @GDScript.load] will not be able to read converted files in an exported project. If you rely on run-time loading of files present within the PCK, set [member ProjectSettings.editor/export/convert_text_resources_to_binary] to [code]false[/code].
176
</description>
177
</method>
178
<method name="ord">
179
<return type="int" />
180
<param index="0" name="char" type="String" />
181
<description>
182
Returns an integer representing the Unicode code point of the given character [param char], which should be a string of length 1.
183
[codeblock]
184
print(ord("A")) # Prints 65
185
print(ord("🤖")) # Prints 129302
186
[/codeblock]
187
This is the inverse of [method char]. See also [method String.chr] and [method String.unicode_at].
188
</description>
189
</method>
190
<method name="preload">
191
<return type="Resource" />
192
<param index="0" name="path" type="String" />
193
<description>
194
Returns a [Resource] from the filesystem located at [param path]. During run-time, the resource is loaded when the script is being parsed. This function effectively acts as a reference to that resource. Note that this function requires [param path] to be a constant [String]. If you want to load a resource from a dynamic/variable path, use [method load].
195
[b]Note:[/b] Resource paths can be obtained by right-clicking on a resource in the Assets Panel and choosing "Copy Path", or by dragging the file from the FileSystem dock into the current script.
196
[codeblock]
197
# Create instance of a scene.
198
var diamond = preload("res://diamond.tscn").instantiate()
199
[/codeblock]
200
[b]Note:[/b] [method preload] is a keyword, not a function. So you cannot access it as a [Callable].
201
</description>
202
</method>
203
<method name="print_debug" qualifiers="vararg">
204
<return type="void" />
205
<description>
206
Like [method @GlobalScope.print], but includes the current stack frame when running with the debugger turned on.
207
The output in the console may look like the following:
208
[codeblock lang=text]
209
Test print
210
At: res://test.gd:15:_process()
211
[/codeblock]
212
See also [method print_stack], [method get_stack], and [method Engine.capture_script_backtraces].
213
[b]Note:[/b] By default, backtraces are only available in editor builds and debug builds. To enable them for release builds as well, you need to enable [member ProjectSettings.debug/settings/gdscript/always_track_call_stacks].
214
</description>
215
</method>
216
<method name="print_stack">
217
<return type="void" />
218
<description>
219
Prints a stack trace at the current code location.
220
The output in the console may look like the following:
221
[codeblock lang=text]
222
Frame 0 - res://test.gd:16 in function '_process'
223
[/codeblock]
224
See also [method print_debug], [method get_stack], and [method Engine.capture_script_backtraces].
225
[b]Note:[/b] By default, backtraces are only available in editor builds and debug builds. To enable them for release builds as well, you need to enable [member ProjectSettings.debug/settings/gdscript/always_track_call_stacks].
226
</description>
227
</method>
228
<method name="range" qualifiers="vararg" keywords="seq">
229
<return type="Array" />
230
<description>
231
Returns an array with the given range. [method range] can be called in three ways:
232
[code]range(n: int)[/code]: Starts from 0, increases by steps of 1, and stops [i]before[/i] [code]n[/code]. The argument [code]n[/code] is [b]exclusive[/b].
233
[code]range(b: int, n: int)[/code]: Starts from [code]b[/code], increases by steps of 1, and stops [i]before[/i] [code]n[/code]. The arguments [code]b[/code] and [code]n[/code] are [b]inclusive[/b] and [b]exclusive[/b], respectively.
234
[code]range(b: int, n: int, s: int)[/code]: Starts from [code]b[/code], increases/decreases by steps of [code]s[/code], and stops [i]before[/i] [code]n[/code]. The arguments [code]b[/code] and [code]n[/code] are [b]inclusive[/b] and [b]exclusive[/b], respectively. The argument [code]s[/code] [b]can[/b] be negative, but not [code]0[/code]. If [code]s[/code] is [code]0[/code], an error message is printed.
235
[method range] converts all arguments to [int] before processing.
236
[b]Note:[/b] Returns an empty array if no value meets the value constraint (e.g. [code]range(2, 5, -1)[/code] or [code]range(5, 5, 1)[/code]).
237
[b]Examples:[/b]
238
[codeblock]
239
print(range(4)) # Prints [0, 1, 2, 3]
240
print(range(2, 5)) # Prints [2, 3, 4]
241
print(range(0, 6, 2)) # Prints [0, 2, 4]
242
print(range(4, 1, -1)) # Prints [4, 3, 2]
243
[/codeblock]
244
To iterate over an [Array] backwards, use:
245
[codeblock]
246
var array = [3, 6, 9]
247
for i in range(array.size() - 1, -1, -1):
248
print(array[i])
249
[/codeblock]
250
Output:
251
[codeblock lang=text]
252
9
253
6
254
3
255
[/codeblock]
256
To iterate over [float], convert them in the loop.
257
[codeblock]
258
for i in range (3, 0, -1):
259
print(i / 10.0)
260
[/codeblock]
261
Output:
262
[codeblock lang=text]
263
0.3
264
0.2
265
0.1
266
[/codeblock]
267
</description>
268
</method>
269
<method name="type_exists">
270
<return type="bool" />
271
<param index="0" name="type" type="StringName" />
272
<description>
273
Returns [code]true[/code] if the given [Object]-derived class exists in [ClassDB]. Note that [Variant] data types are not registered in [ClassDB].
274
[codeblock]
275
type_exists("Sprite2D") # Returns true
276
type_exists("NonExistentClass") # Returns false
277
[/codeblock]
278
</description>
279
</method>
280
</methods>
281
<constants>
282
<constant name="PI" value="3.14159265358979">
283
Constant that represents how many times the diameter of a circle fits around its perimeter. This is equivalent to [code]TAU / 2[/code], or 180 degrees in rotations.
284
</constant>
285
<constant name="TAU" value="6.28318530717959">
286
The circle constant, the circumference of the unit circle in radians. This is equivalent to [code]PI * 2[/code], or 360 degrees in rotations.
287
</constant>
288
<constant name="INF" value="inf">
289
Positive floating-point infinity. This is the result of floating-point division when the divisor is [code]0.0[/code]. For negative infinity, use [code]-INF[/code]. Dividing by [code]-0.0[/code] will result in negative infinity if the numerator is positive, so dividing by [code]0.0[/code] is not the same as dividing by [code]-0.0[/code] (despite [code]0.0 == -0.0[/code] returning [code]true[/code]).
290
[b]Warning:[/b] Numeric infinity is only a concept with floating-point numbers, and has no equivalent for integers. Dividing an integer number by [code]0[/code] will not result in [constant INF] and will result in a run-time error instead.
291
</constant>
292
<constant name="NAN" value="nan">
293
"Not a Number", an invalid floating-point value. It is returned by some invalid operations, such as dividing floating-point [code]0.0[/code] by [code]0.0[/code].
294
[constant NAN] has special properties, including that [code]!=[/code] always returns [code]true[/code], while other comparison operators always return [code]false[/code]. This is true even when comparing with itself ([code]NAN == NAN[/code] returns [code]false[/code] and [code]NAN != NAN[/code] returns [code]true[/code]). Due to this, you must use [method @GlobalScope.is_nan] to check whether a number is equal to [constant NAN].
295
[b]Warning:[/b] "Not a Number" is only a concept with floating-point numbers, and has no equivalent for integers. Dividing an integer [code]0[/code] by [code]0[/code] will not result in [constant NAN] and will result in a run-time error instead.
296
</constant>
297
</constants>
298
<annotations>
299
<annotation name="@abstract">
300
<return type="void" />
301
<description>
302
Marks a class or a method as abstract.
303
An abstract class is a class that cannot be instantiated directly. Instead, it is meant to be inherited by other classes. Attempting to instantiate an abstract class will result in an error.
304
An abstract method is a method that has no implementation. Therefore, a newline or a semicolon is expected after the function header. This defines a contract that inheriting classes must conform to, because the method signature must be compatible when overriding.
305
Inheriting classes must either provide implementations for all abstract methods, or the inheriting class must be marked as abstract. If a class has at least one abstract method (either its own or an unimplemented inherited one), then it must also be marked as abstract. However, the reverse is not true: an abstract class is allowed to have no abstract methods.
306
[codeblock]
307
@abstract class Shape:
308
@abstract func draw()
309
310
class Circle extends Shape:
311
func draw():
312
print("Drawing a circle.")
313
314
class Square extends Shape:
315
func draw():
316
print("Drawing a square.")
317
[/codeblock]
318
</description>
319
</annotation>
320
<annotation name="@export">
321
<return type="void" />
322
<description>
323
Mark the following property as exported (editable in the Inspector dock and saved to disk). To control the type of the exported property, use the type hint notation.
324
[codeblock]
325
extends Node
326
327
enum Direction {LEFT, RIGHT, UP, DOWN}
328
329
# Built-in types.
330
@export var string = ""
331
@export var int_number = 5
332
@export var float_number: float = 5
333
334
# Enums.
335
@export var type: Variant.Type
336
@export var format: Image.Format
337
@export var direction: Direction
338
339
# Resources.
340
@export var image: Image
341
@export var custom_resource: CustomResource
342
343
# Nodes.
344
@export var node: Node
345
@export var custom_node: CustomNode
346
347
# Typed arrays.
348
@export var int_array: Array[int]
349
@export var direction_array: Array[Direction]
350
@export var image_array: Array[Image]
351
@export var node_array: Array[Node]
352
[/codeblock]
353
[b]Note:[/b] Custom resources and nodes should be registered as global classes using [code]class_name[/code], since the Inspector currently only supports global classes. Otherwise, a less specific type will be exported instead.
354
[b]Note:[/b] Node export is only supported in [Node]-derived classes and has a number of other limitations.
355
</description>
356
</annotation>
357
<annotation name="@export_category">
358
<return type="void" />
359
<param index="0" name="name" type="String" />
360
<description>
361
Define a new category for the following exported properties. This helps to organize properties in the Inspector dock.
362
See also [constant PROPERTY_USAGE_CATEGORY].
363
[codeblock]
364
@export_category("Statistics")
365
@export var hp = 30
366
@export var speed = 1.25
367
[/codeblock]
368
[b]Note:[/b] Categories in the Inspector dock's list usually divide properties coming from different classes (Node, Node2D, Sprite, etc.). For better clarity, it's recommended to use [annotation @export_group] and [annotation @export_subgroup], instead.
369
</description>
370
</annotation>
371
<annotation name="@export_color_no_alpha">
372
<return type="void" />
373
<description>
374
Export a [Color], [Array][lb][Color][rb], or [PackedColorArray] property without allowing its transparency ([member Color.a]) to be edited.
375
See also [constant PROPERTY_HINT_COLOR_NO_ALPHA].
376
[codeblock]
377
@export_color_no_alpha var dye_color: Color
378
@export_color_no_alpha var dye_colors: Array[Color]
379
[/codeblock]
380
</description>
381
</annotation>
382
<annotation name="@export_custom">
383
<return type="void" />
384
<param index="0" name="hint" type="int" enum="PropertyHint" />
385
<param index="1" name="hint_string" type="String" />
386
<param index="2" name="usage" type="int" enum="PropertyUsageFlags" is_bitfield="true" default="6" />
387
<description>
388
Allows you to set a custom hint, hint string, and usage flags for the exported property. Note that there's no validation done in GDScript, it will just pass the parameters to the editor.
389
[codeblock]
390
@export_custom(PROPERTY_HINT_NONE, "suffix:m") var suffix: Vector3
391
[/codeblock]
392
[b]Note:[/b] Regardless of the [param usage] value, the [constant PROPERTY_USAGE_SCRIPT_VARIABLE] flag is always added, as with any explicitly declared script variable.
393
</description>
394
</annotation>
395
<annotation name="@export_dir">
396
<return type="void" />
397
<description>
398
Export a [String], [Array][lb][String][rb], or [PackedStringArray] property as a path to a directory. The path will be limited to the project folder and its subfolders. See [annotation @export_global_dir] to allow picking from the entire filesystem.
399
See also [constant PROPERTY_HINT_DIR].
400
[codeblock]
401
@export_dir var sprite_folder_path: String
402
@export_dir var sprite_folder_paths: Array[String]
403
[/codeblock]
404
</description>
405
</annotation>
406
<annotation name="@export_enum" qualifiers="vararg">
407
<return type="void" />
408
<param index="0" name="names" type="String" />
409
<description>
410
Export an [int], [String], [Array][lb][int][rb], [Array][lb][String][rb], [PackedByteArray], [PackedInt32Array], [PackedInt64Array], or [PackedStringArray] property as an enumerated list of options (or an array of options). If the property is an [int], then the index of the value is stored, in the same order the values are provided. You can add explicit values using a colon. If the property is a [String], then the value is stored.
411
See also [constant PROPERTY_HINT_ENUM].
412
[codeblock]
413
@export_enum("Warrior", "Magician", "Thief") var character_class: int
414
@export_enum("Slow:30", "Average:60", "Very Fast:200") var character_speed: int
415
@export_enum("Rebecca", "Mary", "Leah") var character_name: String
416
417
@export_enum("Sword", "Spear", "Mace") var character_items: Array[int]
418
@export_enum("double_jump", "climb", "dash") var character_skills: Array[String]
419
[/codeblock]
420
If you want to set an initial value, you must specify it explicitly:
421
[codeblock]
422
@export_enum("Rebecca", "Mary", "Leah") var character_name: String = "Rebecca"
423
[/codeblock]
424
If you want to use named GDScript enums, then use [annotation @export] instead:
425
[codeblock]
426
enum CharacterName {REBECCA, MARY, LEAH}
427
@export var character_name: CharacterName
428
429
enum CharacterItem {SWORD, SPEAR, MACE}
430
@export var character_items: Array[CharacterItem]
431
[/codeblock]
432
</description>
433
</annotation>
434
<annotation name="@export_exp_easing" qualifiers="vararg">
435
<return type="void" />
436
<param index="0" name="hints" type="String" default="&quot;&quot;" />
437
<description>
438
Export a floating-point property with an easing editor widget. Additional hints can be provided to adjust the behavior of the widget. [code]"attenuation"[/code] flips the curve, which makes it more intuitive for editing attenuation properties. [code]"positive_only"[/code] limits values to only be greater than or equal to zero.
439
See also [constant PROPERTY_HINT_EXP_EASING].
440
[codeblock]
441
@export_exp_easing var transition_speed
442
@export_exp_easing("attenuation") var fading_attenuation
443
@export_exp_easing("positive_only") var effect_power
444
@export_exp_easing var speeds: Array[float]
445
[/codeblock]
446
</description>
447
</annotation>
448
<annotation name="@export_file" qualifiers="vararg">
449
<return type="void" />
450
<param index="0" name="filter" type="String" default="&quot;&quot;" />
451
<description>
452
Export a [String], [Array][lb][String][rb], or [PackedStringArray] property as a path to a file. The path will be limited to the project folder and its subfolders. See [annotation @export_global_file] to allow picking from the entire filesystem.
453
If [param filter] is provided, only matching files will be available for picking.
454
See also [constant PROPERTY_HINT_FILE].
455
[codeblock]
456
@export_file var sound_effect_path: String
457
@export_file("*.txt") var notes_path: String
458
@export_file var level_paths: Array[String]
459
[/codeblock]
460
[b]Note:[/b] The file will be stored and referenced as UID, if available. This ensures that the reference is valid even when the file is moved. You can use [ResourceUID] methods to convert it to path.
461
</description>
462
</annotation>
463
<annotation name="@export_file_path" qualifiers="vararg">
464
<return type="void" />
465
<param index="0" name="filter" type="String" default="&quot;&quot;" />
466
<description>
467
Same as [annotation @export_file], except the file will be stored as a raw path. This means that it may become invalid when the file is moved. If you are exporting a [Resource] path, consider using [annotation @export_file] instead.
468
</description>
469
</annotation>
470
<annotation name="@export_flags" qualifiers="vararg">
471
<return type="void" />
472
<param index="0" name="names" type="String" />
473
<description>
474
Export an integer property as a bit flag field. This allows to store several "checked" or [code]true[/code] values with one property, and comfortably select them from the Inspector dock.
475
See also [constant PROPERTY_HINT_FLAGS].
476
[codeblock]
477
@export_flags("Fire", "Water", "Earth", "Wind") var spell_elements = 0
478
[/codeblock]
479
You can add explicit values using a colon:
480
[codeblock]
481
@export_flags("Self:4", "Allies:8", "Foes:16") var spell_targets = 0
482
[/codeblock]
483
You can also combine several flags:
484
[codeblock]
485
@export_flags("Self:4", "Allies:8", "Self and Allies:12", "Foes:16")
486
var spell_targets = 0
487
[/codeblock]
488
[b]Note:[/b] A flag value must be at least [code]1[/code] and at most [code]2 ** 32 - 1[/code].
489
[b]Note:[/b] Unlike [annotation @export_enum], the previous explicit value is not taken into account. In the following example, A is 16, B is 2, C is 4.
490
[codeblock]
491
@export_flags("A:16", "B", "C") var x
492
[/codeblock]
493
You can also use the annotation on [Array][lb][int][rb], [PackedByteArray], [PackedInt32Array], and [PackedInt64Array]
494
[codeblock]
495
@export_flags("Fire", "Water", "Earth", "Wind") var phase_elements: Array[int]
496
[/codeblock]
497
</description>
498
</annotation>
499
<annotation name="@export_flags_2d_navigation">
500
<return type="void" />
501
<description>
502
Export an integer property as a bit flag field for 2D navigation layers. The widget in the Inspector dock will use the layer names defined in [member ProjectSettings.layer_names/2d_navigation/layer_1].
503
See also [constant PROPERTY_HINT_LAYERS_2D_NAVIGATION].
504
[codeblock]
505
@export_flags_2d_navigation var navigation_layers: int
506
@export_flags_2d_navigation var navigation_layers_array: Array[int]
507
[/codeblock]
508
</description>
509
</annotation>
510
<annotation name="@export_flags_2d_physics">
511
<return type="void" />
512
<description>
513
Export an integer property as a bit flag field for 2D physics layers. The widget in the Inspector dock will use the layer names defined in [member ProjectSettings.layer_names/2d_physics/layer_1].
514
See also [constant PROPERTY_HINT_LAYERS_2D_PHYSICS].
515
[codeblock]
516
@export_flags_2d_physics var physics_layers: int
517
@export_flags_2d_physics var physics_layers_array: Array[int]
518
[/codeblock]
519
</description>
520
</annotation>
521
<annotation name="@export_flags_2d_render">
522
<return type="void" />
523
<description>
524
Export an integer property as a bit flag field for 2D render layers. The widget in the Inspector dock will use the layer names defined in [member ProjectSettings.layer_names/2d_render/layer_1].
525
See also [constant PROPERTY_HINT_LAYERS_2D_RENDER].
526
[codeblock]
527
@export_flags_2d_render var render_layers: int
528
@export_flags_2d_render var render_layers_array: Array[int]
529
[/codeblock]
530
</description>
531
</annotation>
532
<annotation name="@export_flags_3d_navigation">
533
<return type="void" />
534
<description>
535
Export an integer property as a bit flag field for 3D navigation layers. The widget in the Inspector dock will use the layer names defined in [member ProjectSettings.layer_names/3d_navigation/layer_1].
536
See also [constant PROPERTY_HINT_LAYERS_3D_NAVIGATION].
537
[codeblock]
538
@export_flags_3d_navigation var navigation_layers: int
539
@export_flags_3d_navigation var navigation_layers_array: Array[int]
540
[/codeblock]
541
</description>
542
</annotation>
543
<annotation name="@export_flags_3d_physics">
544
<return type="void" />
545
<description>
546
Export an integer property as a bit flag field for 3D physics layers. The widget in the Inspector dock will use the layer names defined in [member ProjectSettings.layer_names/3d_physics/layer_1].
547
See also [constant PROPERTY_HINT_LAYERS_3D_PHYSICS].
548
[codeblock]
549
@export_flags_3d_physics var physics_layers: int
550
@export_flags_3d_physics var physics_layers_array: Array[int]
551
[/codeblock]
552
</description>
553
</annotation>
554
<annotation name="@export_flags_3d_render">
555
<return type="void" />
556
<description>
557
Export an integer property as a bit flag field for 3D render layers. The widget in the Inspector dock will use the layer names defined in [member ProjectSettings.layer_names/3d_render/layer_1].
558
See also [constant PROPERTY_HINT_LAYERS_3D_RENDER].
559
[codeblock]
560
@export_flags_3d_render var render_layers: int
561
@export_flags_3d_render var render_layers_array: Array[int]
562
[/codeblock]
563
</description>
564
</annotation>
565
<annotation name="@export_flags_avoidance">
566
<return type="void" />
567
<description>
568
Export an integer property as a bit flag field for navigation avoidance layers. The widget in the Inspector dock will use the layer names defined in [member ProjectSettings.layer_names/avoidance/layer_1].
569
See also [constant PROPERTY_HINT_LAYERS_AVOIDANCE].
570
[codeblock]
571
@export_flags_avoidance var avoidance_layers: int
572
@export_flags_avoidance var avoidance_layers_array: Array[int]
573
[/codeblock]
574
</description>
575
</annotation>
576
<annotation name="@export_global_dir">
577
<return type="void" />
578
<description>
579
Export a [String], [Array][lb][String][rb], or [PackedStringArray] property as an absolute path to a directory. The path can be picked from the entire filesystem. See [annotation @export_dir] to limit it to the project folder and its subfolders.
580
See also [constant PROPERTY_HINT_GLOBAL_DIR].
581
[codeblock]
582
@export_global_dir var sprite_folder_path: String
583
@export_global_dir var sprite_folder_paths: Array[String]
584
[/codeblock]
585
</description>
586
</annotation>
587
<annotation name="@export_global_file" qualifiers="vararg">
588
<return type="void" />
589
<param index="0" name="filter" type="String" default="&quot;&quot;" />
590
<description>
591
Export a [String], [Array][lb][String][rb], or [PackedStringArray] property as an absolute path to a file. The path can be picked from the entire filesystem. See [annotation @export_file] to limit it to the project folder and its subfolders.
592
If [param filter] is provided, only matching files will be available for picking.
593
See also [constant PROPERTY_HINT_GLOBAL_FILE].
594
[codeblock]
595
@export_global_file var sound_effect_path: String
596
@export_global_file("*.txt") var notes_path: String
597
@export_global_file var multiple_paths: Array[String]
598
[/codeblock]
599
</description>
600
</annotation>
601
<annotation name="@export_group">
602
<return type="void" />
603
<param index="0" name="name" type="String" />
604
<param index="1" name="prefix" type="String" default="&quot;&quot;" />
605
<description>
606
Define a new group for the following exported properties. This helps to organize properties in the Inspector dock. Groups can be added with an optional [param prefix], which would make group to only consider properties that have this prefix. The grouping will break on the first property that doesn't have a prefix. The prefix is also removed from the property's name in the Inspector dock.
607
If no [param prefix] is provided, then every following property will be added to the group. The group ends when then next group or category is defined. You can also force end a group by using this annotation with empty strings for parameters, [code]@export_group("", "")[/code].
608
Groups cannot be nested, use [annotation @export_subgroup] to add subgroups within groups.
609
See also [constant PROPERTY_USAGE_GROUP].
610
[codeblock]
611
@export_group("Racer Properties")
612
@export var nickname = "Nick"
613
@export var age = 26
614
615
@export_group("Car Properties", "car_")
616
@export var car_label = "Speedy"
617
@export var car_number = 3
618
619
@export_group("", "")
620
@export var ungrouped_number = 3
621
[/codeblock]
622
</description>
623
</annotation>
624
<annotation name="@export_multiline">
625
<return type="void" />
626
<description>
627
Export a [String], [Array][lb][String][rb], [PackedStringArray], [Dictionary] or [Array][lb][Dictionary][rb] property with a large [TextEdit] widget instead of a [LineEdit]. This adds support for multiline content and makes it easier to edit large amount of text stored in the property.
628
See also [constant PROPERTY_HINT_MULTILINE_TEXT].
629
[codeblock]
630
@export_multiline var character_biography
631
@export_multiline var npc_dialogs: Array[String]
632
[/codeblock]
633
</description>
634
</annotation>
635
<annotation name="@export_node_path" qualifiers="vararg">
636
<return type="void" />
637
<param index="0" name="type" type="String" default="&quot;&quot;" />
638
<description>
639
Export a [NodePath] or [Array][lb][NodePath][rb] property with a filter for allowed node types.
640
See also [constant PROPERTY_HINT_NODE_PATH_VALID_TYPES].
641
[codeblock]
642
@export_node_path("Button", "TouchScreenButton") var some_button
643
@export_node_path("Button", "TouchScreenButton") var many_buttons: Array[NodePath]
644
[/codeblock]
645
[b]Note:[/b] The type must be a native class or a globally registered script (using the [code]class_name[/code] keyword) that inherits [Node].
646
</description>
647
</annotation>
648
<annotation name="@export_placeholder">
649
<return type="void" />
650
<param index="0" name="placeholder" type="String" />
651
<description>
652
Export a [String], [Array][lb][String][rb], or [PackedStringArray] property with a placeholder text displayed in the editor widget when no value is present.
653
See also [constant PROPERTY_HINT_PLACEHOLDER_TEXT].
654
[codeblock]
655
@export_placeholder("Name in lowercase") var character_id: String
656
@export_placeholder("Name in lowercase") var friend_ids: Array[String]
657
[/codeblock]
658
</description>
659
</annotation>
660
<annotation name="@export_range" qualifiers="vararg">
661
<return type="void" />
662
<param index="0" name="min" type="float" />
663
<param index="1" name="max" type="float" />
664
<param index="2" name="step" type="float" default="1.0" />
665
<param index="3" name="extra_hints" type="String" default="&quot;&quot;" />
666
<description>
667
Export an [int], [float], [Array][lb][int][rb], [Array][lb][float][rb], [PackedByteArray], [PackedInt32Array], [PackedInt64Array], [PackedFloat32Array], or [PackedFloat64Array] property as a range value. The range must be defined by [param min] and [param max], as well as an optional [param step] and a variety of extra hints. The [param step] defaults to [code]1[/code] for integer properties. For floating-point numbers this value depends on your [member EditorSettings.interface/inspector/default_float_step] setting.
668
If hints [code]"or_greater"[/code] and [code]"or_less"[/code] are provided, the editor widget will not cap the value at range boundaries. The [code]"exp"[/code] hint will make the edited values on range to change exponentially. The [code]"hide_slider"[/code] hint will hide the slider element of the editor widget.
669
Hints also allow to indicate the units for the edited value. Using [code]"radians_as_degrees"[/code] you can specify that the actual value is in radians, but should be displayed in degrees in the Inspector dock (the range values are also in degrees). [code]"degrees"[/code] allows to add a degree sign as a unit suffix (the value is unchanged). Finally, a custom suffix can be provided using [code]"suffix:unit"[/code], where "unit" can be any string.
670
See also [constant PROPERTY_HINT_RANGE].
671
[codeblock]
672
@export_range(0, 20) var number
673
@export_range(-10, 20) var number
674
@export_range(-10, 20, 0.2) var number: float
675
@export_range(0, 20) var numbers: Array[float]
676
677
@export_range(0, 100, 1, "or_greater") var power_percent
678
@export_range(0, 100, 1, "or_greater", "or_less") var health_delta
679
680
@export_range(-180, 180, 0.001, "radians_as_degrees") var angle_radians
681
@export_range(0, 360, 1, "degrees") var angle_degrees
682
@export_range(-8, 8, 2, "suffix:px") var target_offset
683
[/codeblock]
684
</description>
685
</annotation>
686
<annotation name="@export_storage">
687
<return type="void" />
688
<description>
689
Export a property with [constant PROPERTY_USAGE_STORAGE] flag. The property is not displayed in the editor, but it is serialized and stored in the scene or resource file. This can be useful for [annotation @tool] scripts. Also the property value is copied when [method Resource.duplicate] or [method Node.duplicate] is called, unlike non-exported variables.
690
[codeblock]
691
var a # Not stored in the file, not displayed in the editor.
692
@export_storage var b # Stored in the file, not displayed in the editor.
693
@export var c: int # Stored in the file, displayed in the editor.
694
[/codeblock]
695
</description>
696
</annotation>
697
<annotation name="@export_subgroup">
698
<return type="void" />
699
<param index="0" name="name" type="String" />
700
<param index="1" name="prefix" type="String" default="&quot;&quot;" />
701
<description>
702
Define a new subgroup for the following exported properties. This helps to organize properties in the Inspector dock. Subgroups work exactly like groups, except they need a parent group to exist. See [annotation @export_group].
703
See also [constant PROPERTY_USAGE_SUBGROUP].
704
[codeblock]
705
@export_group("Racer Properties")
706
@export var nickname = "Nick"
707
@export var age = 26
708
709
@export_subgroup("Car Properties", "car_")
710
@export var car_label = "Speedy"
711
@export var car_number = 3
712
[/codeblock]
713
[b]Note:[/b] Subgroups cannot be nested, but you can use the slash separator ([code]/[/code]) to achieve the desired effect:
714
[codeblock]
715
@export_group("Car Properties")
716
@export_subgroup("Wheels", "wheel_")
717
@export_subgroup("Wheels/Front", "front_wheel_")
718
@export var front_wheel_strength = 10
719
@export var front_wheel_mobility = 5
720
@export_subgroup("Wheels/Rear", "rear_wheel_")
721
@export var rear_wheel_strength = 8
722
@export var rear_wheel_mobility = 3
723
@export_subgroup("Wheels", "wheel_")
724
@export var wheel_material: PhysicsMaterial
725
[/codeblock]
726
</description>
727
</annotation>
728
<annotation name="@export_tool_button">
729
<return type="void" />
730
<param index="0" name="text" type="String" />
731
<param index="1" name="icon" type="String" default="&quot;&quot;" />
732
<description>
733
Export a [Callable] property as a clickable button with the label [param text]. When the button is pressed, the callable is called.
734
If [param icon] is specified, it is used to fetch an icon for the button via [method Control.get_theme_icon], from the [code]"EditorIcons"[/code] theme type. If [param icon] is omitted, the default [code]"Callable"[/code] icon is used instead.
735
Consider using the [EditorUndoRedoManager] to allow the action to be reverted safely.
736
See also [constant PROPERTY_HINT_TOOL_BUTTON].
737
[codeblock]
738
@tool
739
extends Sprite2D
740
741
@export_tool_button("Hello") var hello_action = hello
742
@export_tool_button("Randomize the color!", "ColorRect")
743
var randomize_color_action = randomize_color
744
745
func hello():
746
print("Hello world!")
747
748
func randomize_color():
749
var undo_redo = EditorInterface.get_editor_undo_redo()
750
undo_redo.create_action("Randomized Sprite2D Color")
751
undo_redo.add_do_property(self, &amp;"self_modulate", Color(randf(), randf(), randf()))
752
undo_redo.add_undo_property(self, &amp;"self_modulate", self_modulate)
753
undo_redo.commit_action()
754
[/codeblock]
755
[b]Note:[/b] The property is exported without the [constant PROPERTY_USAGE_STORAGE] flag because a [Callable] cannot be properly serialized and stored in a file.
756
[b]Note:[/b] In an exported project neither [EditorInterface] nor [EditorUndoRedoManager] exist, which may cause some scripts to break. To prevent this, you can use [method Engine.get_singleton] and omit the static type from the variable declaration:
757
[codeblock]
758
var undo_redo = Engine.get_singleton(&amp;"EditorInterface").get_editor_undo_redo()
759
[/codeblock]
760
[b]Note:[/b] Avoid storing lambda callables in member variables of [RefCounted]-based classes (e.g. resources), as this can lead to memory leaks. Use only method callables and optionally [method Callable.bind] or [method Callable.unbind].
761
</description>
762
</annotation>
763
<annotation name="@icon">
764
<return type="void" />
765
<param index="0" name="icon_path" type="String" />
766
<description>
767
Add a custom icon to the current script. The icon specified at [param icon_path] is displayed in the Scene dock for every node of that class, as well as in various editor dialogs.
768
[codeblock]
769
@icon("res://path/to/class/icon.svg")
770
[/codeblock]
771
[b]Note:[/b] Only the script can have a custom icon. Inner classes are not supported.
772
[b]Note:[/b] As annotations describe their subject, the [annotation @icon] annotation must be placed before the class definition and inheritance.
773
[b]Note:[/b] Unlike most other annotations, the argument of the [annotation @icon] annotation must be a string literal (constant expressions are not supported).
774
</description>
775
</annotation>
776
<annotation name="@onready">
777
<return type="void" />
778
<description>
779
Mark the following property as assigned when the [Node] is ready. Values for these properties are not assigned immediately when the node is initialized ([method Object._init]), and instead are computed and stored right before [method Node._ready].
780
[codeblock]
781
@onready var character_name = $Label
782
[/codeblock]
783
</description>
784
</annotation>
785
<annotation name="@rpc">
786
<return type="void" />
787
<param index="0" name="mode" type="String" default="&quot;authority&quot;" />
788
<param index="1" name="sync" type="String" default="&quot;call_remote&quot;" />
789
<param index="2" name="transfer_mode" type="String" default="&quot;unreliable&quot;" />
790
<param index="3" name="transfer_channel" type="int" default="0" />
791
<description>
792
Mark the following method for remote procedure calls. See [url=$DOCS_URL/tutorials/networking/high_level_multiplayer.html]High-level multiplayer[/url].
793
If [param mode] is set as [code]"any_peer"[/code], allows any peer to call this RPC function. Otherwise, only the authority peer is allowed to call it and [param mode] should be kept as [code]"authority"[/code]. When configuring functions as RPCs with [method Node.rpc_config], each of these modes respectively corresponds to the [constant MultiplayerAPI.RPC_MODE_AUTHORITY] and [constant MultiplayerAPI.RPC_MODE_ANY_PEER] RPC modes. See [enum MultiplayerAPI.RPCMode]. If a peer that is not the authority tries to call a function that is only allowed for the authority, the function will not be executed. If the error can be detected locally (when the RPC configuration is consistent between the local and the remote peer), an error message will be displayed on the sender peer. Otherwise, the remote peer will detect the error and print an error there.
794
If [param sync] is set as [code]"call_remote"[/code], the function will only be executed on the remote peer, but not locally. To run this function locally too, set [param sync] to [code]"call_local"[/code]. When configuring functions as RPCs with [method Node.rpc_config], this is equivalent to setting [code]call_local[/code] to [code]true[/code].
795
The [param transfer_mode] accepted values are [code]"unreliable"[/code], [code]"unreliable_ordered"[/code], or [code]"reliable"[/code]. It sets the transfer mode of the underlying [MultiplayerPeer]. See [member MultiplayerPeer.transfer_mode].
796
The [param transfer_channel] defines the channel of the underlying [MultiplayerPeer]. See [member MultiplayerPeer.transfer_channel].
797
The order of [param mode], [param sync] and [param transfer_mode] does not matter, but values related to the same argument must not be used more than once. [param transfer_channel] always has to be the 4th argument (you must specify 3 preceding arguments).
798
[codeblock]
799
@rpc
800
func fn(): pass
801
802
@rpc("any_peer", "unreliable_ordered")
803
func fn_update_pos(): pass
804
805
@rpc("authority", "call_remote", "unreliable", 0) # Equivalent to @rpc
806
func fn_default(): pass
807
[/codeblock]
808
[b]Note:[/b] Methods annotated with [annotation @rpc] cannot receive objects which define required parameters in [method Object._init]. See [method Object._init] for more details.
809
</description>
810
</annotation>
811
<annotation name="@static_unload">
812
<return type="void" />
813
<description>
814
Make a script with static variables to not persist after all references are lost. If the script is loaded again the static variables will revert to their default values.
815
[b]Note:[/b] As annotations describe their subject, the [annotation @static_unload] annotation must be placed before the class definition and inheritance.
816
[b]Warning:[/b] Currently, due to a bug, scripts are never freed, even if [annotation @static_unload] annotation is used.
817
</description>
818
</annotation>
819
<annotation name="@tool">
820
<return type="void" />
821
<description>
822
Mark the current script as a tool script, allowing it to be loaded and executed by the editor. See [url=$DOCS_URL/tutorials/plugins/running_code_in_the_editor.html]Running code in the editor[/url].
823
[codeblock]
824
@tool
825
extends Node
826
[/codeblock]
827
[b]Note:[/b] As annotations describe their subject, the [annotation @tool] annotation must be placed before the class definition and inheritance.
828
</description>
829
</annotation>
830
<annotation name="@warning_ignore" qualifiers="vararg">
831
<return type="void" />
832
<param index="0" name="warning" type="String" />
833
<description>
834
Mark the following statement to ignore the specified [param warning]. See [url=$DOCS_URL/tutorials/scripting/gdscript/warning_system.html]GDScript warning system[/url].
835
[codeblock]
836
func test():
837
print("hello")
838
return
839
@warning_ignore("unreachable_code")
840
print("unreachable")
841
[/codeblock]
842
See also [annotation @warning_ignore_start] and [annotation @warning_ignore_restore].
843
</description>
844
</annotation>
845
<annotation name="@warning_ignore_restore" qualifiers="vararg">
846
<return type="void" />
847
<param index="0" name="warning" type="String" />
848
<description>
849
Stops ignoring the listed warning types after [annotation @warning_ignore_start]. Ignoring the specified warning types will be reset to Project Settings. This annotation can be omitted to ignore the warning types until the end of the file.
850
[b]Note:[/b] Unlike most other annotations, arguments of the [annotation @warning_ignore_restore] annotation must be string literals (constant expressions are not supported).
851
</description>
852
</annotation>
853
<annotation name="@warning_ignore_start" qualifiers="vararg">
854
<return type="void" />
855
<param index="0" name="warning" type="String" />
856
<description>
857
Starts ignoring the listed warning types until the end of the file or the [annotation @warning_ignore_restore] annotation with the given warning type.
858
[codeblock]
859
func test():
860
var a = 1 # Warning (if enabled in the Project Settings).
861
@warning_ignore_start("unused_variable")
862
var b = 2 # No warning.
863
var c = 3 # No warning.
864
@warning_ignore_restore("unused_variable")
865
var d = 4 # Warning (if enabled in the Project Settings).
866
[/codeblock]
867
[b]Note:[/b] To suppress a single warning, use [annotation @warning_ignore] instead.
868
[b]Note:[/b] Unlike most other annotations, arguments of the [annotation @warning_ignore_start] annotation must be string literals (constant expressions are not supported).
869
</description>
870
</annotation>
871
</annotations>
872
</class>
873
874