@GDScript.xml 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="@GDScript" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
  3. <brief_description>
  4. Built-in GDScript functions.
  5. </brief_description>
  6. <description>
  7. A list of GDScript-specific utility functions and annotations accessible from any script.
  8. For the list of the global functions and constants 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">
  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. </description>
  47. </method>
  48. <method name="char">
  49. <return type="String" />
  50. <param index="0" name="char" type="int" />
  51. <description>
  52. Returns a single character (as a [String]) of the given Unicode code point (which is compatible with ASCII code).
  53. [codeblock]
  54. a = char(65) # a is "A"
  55. a = char(65 + 32) # a is "a"
  56. a = char(8364) # a is "€"
  57. [/codeblock]
  58. </description>
  59. </method>
  60. <method name="convert">
  61. <return type="Variant" />
  62. <param index="0" name="what" type="Variant" />
  63. <param index="1" name="type" type="int" />
  64. <description>
  65. Converts [param what] to [param type] in the best way possible. The [param type] uses the [enum Variant.Type] values.
  66. [codeblock]
  67. var a = [4, 2.5, 1.2]
  68. print(a is Array) # Prints true
  69. var b = convert(a, TYPE_PACKED_BYTE_ARRAY)
  70. print(b) # Prints [4, 2, 1]
  71. print(b is Array) # Prints false
  72. [/codeblock]
  73. </description>
  74. </method>
  75. <method name="dict_to_inst">
  76. <return type="Object" />
  77. <param index="0" name="dictionary" type="Dictionary" />
  78. <description>
  79. Converts a [param dictionary] (created with [method inst_to_dict]) back to an Object instance. Can be useful for deserializing.
  80. </description>
  81. </method>
  82. <method name="get_stack">
  83. <return type="Array" />
  84. <description>
  85. Returns an array of dictionaries representing the current call stack. See also [method print_stack].
  86. [codeblock]
  87. func _ready():
  88. foo()
  89. func foo():
  90. bar()
  91. func bar():
  92. print(get_stack())
  93. [/codeblock]
  94. Starting from [code]_ready()[/code], [code]bar()[/code] would print:
  95. [codeblock]
  96. [{function:bar, line:12, source:res://script.gd}, {function:foo, line:9, source:res://script.gd}, {function:_ready, line:6, source:res://script.gd}]
  97. [/codeblock]
  98. [b]Note:[/b] This function only works if the running instance is connected to a debugging server (i.e. an editor instance). [method get_stack] will not work in projects exported in release mode, or in projects exported in debug mode if not connected to a debugging server.
  99. [b]Note:[/b] Calling this function from a [Thread] is not supported. Doing so will return an empty array.
  100. </description>
  101. </method>
  102. <method name="inst_to_dict">
  103. <return type="Dictionary" />
  104. <param index="0" name="instance" type="Object" />
  105. <description>
  106. Returns the passed [param instance] converted to a Dictionary. Can be useful for serializing.
  107. [b]Note:[/b] Cannot be used to serialize objects with built-in scripts attached or objects allocated within built-in scripts.
  108. [codeblock]
  109. var foo = "bar"
  110. func _ready():
  111. var d = inst_to_dict(self)
  112. print(d.keys())
  113. print(d.values())
  114. [/codeblock]
  115. Prints out:
  116. [codeblock]
  117. [@subpath, @path, foo]
  118. [, res://test.gd, bar]
  119. [/codeblock]
  120. </description>
  121. </method>
  122. <method name="is_instance_of">
  123. <return type="bool" />
  124. <param index="0" name="value" type="Variant" />
  125. <param index="1" name="type" type="Variant" />
  126. <description>
  127. Returns [code]true[/code] if [param value] is an instance of [param type]. The [param type] value must be one of the following:
  128. - A constant from the [enum Variant.Type] enumeration, for example [constant TYPE_INT].
  129. - An [Object]-derived class which exists in [ClassDB], for example [Node].
  130. - A [Script] (you can use any class, including inner one).
  131. 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) and is more performant. Use the operator instead of this method if you do not need dynamic type checking.
  132. Examples:
  133. [codeblock]
  134. print(is_instance_of(a, TYPE_INT))
  135. print(is_instance_of(a, Node))
  136. print(is_instance_of(a, MyClass))
  137. print(is_instance_of(a, MyClass.InnerClass))
  138. [/codeblock]
  139. [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 an runtime error.
  140. See also [method @GlobalScope.typeof], [method type_exists], [method Array.is_same_typed] (and other [Array] methods).
  141. </description>
  142. </method>
  143. <method name="len">
  144. <return type="int" />
  145. <param index="0" name="var" type="Variant" />
  146. <description>
  147. Returns the length of the given Variant [param var]. The length can be the character count of a [String], 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.
  148. [codeblock]
  149. a = [1, 2, 3, 4]
  150. len(a) # Returns 4
  151. b = "Hello!"
  152. len(b) # Returns 6
  153. [/codeblock]
  154. </description>
  155. </method>
  156. <method name="load">
  157. <return type="Resource" />
  158. <param index="0" name="path" type="String" />
  159. <description>
  160. 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].
  161. [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.
  162. [codeblock]
  163. # Load a scene called "main" located in the root of the project directory and cache it in a variable.
  164. var main = load("res://main.tscn") # main will contain a PackedScene resource.
  165. [/codeblock]
  166. [b]Important:[/b] The path must be absolute. A relative path will always return [code]null[/code].
  167. This function is a simplified version of [method ResourceLoader.load], which can be used for more advanced scenarios.
  168. [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].
  169. </description>
  170. </method>
  171. <method name="preload">
  172. <return type="Resource" />
  173. <param index="0" name="path" type="String" />
  174. <description>
  175. 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].
  176. [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.
  177. [codeblock]
  178. # Create instance of a scene.
  179. var diamond = preload("res://diamond.tscn").instantiate()
  180. [/codeblock]
  181. </description>
  182. </method>
  183. <method name="print_debug" qualifiers="vararg">
  184. <return type="void" />
  185. <description>
  186. Like [method @GlobalScope.print], but includes the current stack frame when running with the debugger turned on.
  187. The output in the console may look like the following:
  188. [codeblock]
  189. Test print
  190. At: res://test.gd:15:_process()
  191. [/codeblock]
  192. [b]Note:[/b] Calling this function from a [Thread] is not supported. Doing so will instead print the thread ID.
  193. </description>
  194. </method>
  195. <method name="print_stack">
  196. <return type="void" />
  197. <description>
  198. Prints a stack trace at the current code location. See also [method get_stack].
  199. The output in the console may look like the following:
  200. [codeblock]
  201. Frame 0 - res://test.gd:16 in function '_process'
  202. [/codeblock]
  203. [b]Note:[/b] This function only works if the running instance is connected to a debugging server (i.e. an editor instance). [method print_stack] will not work in projects exported in release mode, or in projects exported in debug mode if not connected to a debugging server.
  204. [b]Note:[/b] Calling this function from a [Thread] is not supported. Doing so will instead print the thread ID.
  205. </description>
  206. </method>
  207. <method name="range" qualifiers="vararg">
  208. <return type="Array" />
  209. <description>
  210. Returns an array with the given range. [method range] can be called in three ways:
  211. [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].
  212. [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.
  213. [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.
  214. [method range] converts all arguments to [int] before processing.
  215. [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]).
  216. Examples:
  217. [codeblock]
  218. print(range(4)) # Prints [0, 1, 2, 3]
  219. print(range(2, 5)) # Prints [2, 3, 4]
  220. print(range(0, 6, 2)) # Prints [0, 2, 4]
  221. print(range(4, 1, -1)) # Prints [4, 3, 2]
  222. [/codeblock]
  223. To iterate over an [Array] backwards, use:
  224. [codeblock]
  225. var array = [3, 6, 9]
  226. for i in range(array.size(), 0, -1):
  227. print(array[i - 1])
  228. [/codeblock]
  229. Output:
  230. [codeblock]
  231. 9
  232. 6
  233. 3
  234. [/codeblock]
  235. To iterate over [float], convert them in the loop.
  236. [codeblock]
  237. for i in range (3, 0, -1):
  238. print(i / 10.0)
  239. [/codeblock]
  240. Output:
  241. [codeblock]
  242. 0.3
  243. 0.2
  244. 0.1
  245. [/codeblock]
  246. </description>
  247. </method>
  248. <method name="type_exists">
  249. <return type="bool" />
  250. <param index="0" name="type" type="StringName" />
  251. <description>
  252. Returns [code]true[/code] if the given [Object]-derived class exists in [ClassDB]. Note that [Variant] data types are not registered in [ClassDB].
  253. [codeblock]
  254. type_exists("Sprite2D") # Returns true
  255. type_exists("NonExistentClass") # Returns false
  256. [/codeblock]
  257. </description>
  258. </method>
  259. </methods>
  260. <constants>
  261. <constant name="PI" value="3.14159265358979">
  262. 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.
  263. </constant>
  264. <constant name="TAU" value="6.28318530717959">
  265. The circle constant, the circumference of the unit circle in radians. This is equivalent to [code]PI * 2[/code], or 360 degrees in rotations.
  266. </constant>
  267. <constant name="INF" value="inf">
  268. 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]).
  269. [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.
  270. </constant>
  271. <constant name="NAN" value="nan">
  272. "Not a Number", an invalid floating-point value. [constant NAN] has special properties, including that it is not equal to itself ([code]NAN == NAN[/code] returns [code]false[/code]). It is output by some invalid operations, such as dividing floating-point [code]0.0[/code] by [code]0.0[/code].
  273. [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.
  274. </constant>
  275. </constants>
  276. <annotations>
  277. <annotation name="@export">
  278. <return type="void" />
  279. <description>
  280. 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.
  281. [codeblock]
  282. @export var string = ""
  283. @export var int_number = 5
  284. @export var float_number: float = 5
  285. @export var image: Image
  286. [/codeblock]
  287. </description>
  288. </annotation>
  289. <annotation name="@export_category">
  290. <return type="void" />
  291. <param index="0" name="name" type="String" />
  292. <description>
  293. Define a new category for the following exported properties. This helps to organize properties in the Inspector dock.
  294. See also [constant PROPERTY_USAGE_CATEGORY].
  295. [codeblock]
  296. @export_category("Statistics")
  297. @export var hp = 30
  298. @export var speed = 1.25
  299. [/codeblock]
  300. [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.
  301. </description>
  302. </annotation>
  303. <annotation name="@export_color_no_alpha">
  304. <return type="void" />
  305. <description>
  306. Export a [Color] property without allowing its transparency ([member Color.a]) to be edited.
  307. See also [constant PROPERTY_HINT_COLOR_NO_ALPHA].
  308. [codeblock]
  309. @export_color_no_alpha var dye_color: Color
  310. [/codeblock]
  311. </description>
  312. </annotation>
  313. <annotation name="@export_dir">
  314. <return type="void" />
  315. <description>
  316. Export a [String] 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.
  317. See also [constant PROPERTY_HINT_DIR].
  318. [codeblock]
  319. @export_dir var sprite_folder_path: String
  320. [/codeblock]
  321. </description>
  322. </annotation>
  323. <annotation name="@export_enum" qualifiers="vararg">
  324. <return type="void" />
  325. <param index="0" name="names" type="String" />
  326. <description>
  327. Export an [int] or [String] property as an enumerated list 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.
  328. See also [constant PROPERTY_HINT_ENUM].
  329. [codeblock]
  330. @export_enum("Warrior", "Magician", "Thief") var character_class: int
  331. @export_enum("Slow:30", "Average:60", "Very Fast:200") var character_speed: int
  332. @export_enum("Rebecca", "Mary", "Leah") var character_name: String
  333. [/codeblock]
  334. If you want to set an initial value, you must specify it explicitly:
  335. [codeblock]
  336. @export_enum("Rebecca", "Mary", "Leah") var character_name: String = "Rebecca"
  337. [/codeblock]
  338. If you want to use named GDScript enums, then use [annotation @export] instead:
  339. [codeblock]
  340. enum CharacterName {REBECCA, MARY, LEAH}
  341. @export var character_name: CharacterName
  342. [/codeblock]
  343. </description>
  344. </annotation>
  345. <annotation name="@export_exp_easing" qualifiers="vararg">
  346. <return type="void" />
  347. <param index="0" name="hints" type="String" default="&quot;&quot;" />
  348. <description>
  349. 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.
  350. See also [constant PROPERTY_HINT_EXP_EASING].
  351. [codeblock]
  352. @export_exp_easing var transition_speed
  353. @export_exp_easing("attenuation") var fading_attenuation
  354. @export_exp_easing("positive_only") var effect_power
  355. [/codeblock]
  356. </description>
  357. </annotation>
  358. <annotation name="@export_file" qualifiers="vararg">
  359. <return type="void" />
  360. <param index="0" name="filter" type="String" default="&quot;&quot;" />
  361. <description>
  362. Export a [String] 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.
  363. If [param filter] is provided, only matching files will be available for picking.
  364. See also [constant PROPERTY_HINT_FILE].
  365. [codeblock]
  366. @export_file var sound_effect_path: String
  367. @export_file("*.txt") var notes_path: String
  368. [/codeblock]
  369. </description>
  370. </annotation>
  371. <annotation name="@export_flags" qualifiers="vararg">
  372. <return type="void" />
  373. <param index="0" name="names" type="String" />
  374. <description>
  375. 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.
  376. See also [constant PROPERTY_HINT_FLAGS].
  377. [codeblock]
  378. @export_flags("Fire", "Water", "Earth", "Wind") var spell_elements = 0
  379. [/codeblock]
  380. You can add explicit values using a colon:
  381. [codeblock]
  382. @export_flags("Self:4", "Allies:8", "Foes:16") var spell_targets = 0
  383. [/codeblock]
  384. You can also combine several flags:
  385. [codeblock]
  386. @export_flags("Self:4", "Allies:8", "Self and Allies:12", "Foes:16")
  387. var spell_targets = 0
  388. [/codeblock]
  389. [b]Note:[/b] A flag value must be at least [code]1[/code] and at most [code]2 ** 32 - 1[/code].
  390. [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.
  391. [codeblock]
  392. @export_flags("A:16", "B", "C") var x
  393. [/codeblock]
  394. </description>
  395. </annotation>
  396. <annotation name="@export_flags_2d_navigation">
  397. <return type="void" />
  398. <description>
  399. 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].
  400. See also [constant PROPERTY_HINT_LAYERS_2D_NAVIGATION].
  401. [codeblock]
  402. @export_flags_2d_navigation var navigation_layers: int
  403. [/codeblock]
  404. </description>
  405. </annotation>
  406. <annotation name="@export_flags_2d_physics">
  407. <return type="void" />
  408. <description>
  409. 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].
  410. See also [constant PROPERTY_HINT_LAYERS_2D_PHYSICS].
  411. [codeblock]
  412. @export_flags_2d_physics var physics_layers: int
  413. [/codeblock]
  414. </description>
  415. </annotation>
  416. <annotation name="@export_flags_2d_render">
  417. <return type="void" />
  418. <description>
  419. 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].
  420. See also [constant PROPERTY_HINT_LAYERS_2D_RENDER].
  421. [codeblock]
  422. @export_flags_2d_render var render_layers: int
  423. [/codeblock]
  424. </description>
  425. </annotation>
  426. <annotation name="@export_flags_3d_navigation">
  427. <return type="void" />
  428. <description>
  429. 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].
  430. See also [constant PROPERTY_HINT_LAYERS_3D_NAVIGATION].
  431. [codeblock]
  432. @export_flags_3d_navigation var navigation_layers: int
  433. [/codeblock]
  434. </description>
  435. </annotation>
  436. <annotation name="@export_flags_3d_physics">
  437. <return type="void" />
  438. <description>
  439. 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].
  440. See also [constant PROPERTY_HINT_LAYERS_3D_PHYSICS].
  441. [codeblock]
  442. @export_flags_3d_physics var physics_layers: int
  443. [/codeblock]
  444. </description>
  445. </annotation>
  446. <annotation name="@export_flags_3d_render">
  447. <return type="void" />
  448. <description>
  449. 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].
  450. See also [constant PROPERTY_HINT_LAYERS_3D_RENDER].
  451. [codeblock]
  452. @export_flags_3d_render var render_layers: int
  453. [/codeblock]
  454. </description>
  455. </annotation>
  456. <annotation name="@export_global_dir">
  457. <return type="void" />
  458. <description>
  459. Export a [String] 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.
  460. See also [constant PROPERTY_HINT_GLOBAL_DIR].
  461. [codeblock]
  462. @export_global_dir var sprite_folder_path: String
  463. [/codeblock]
  464. </description>
  465. </annotation>
  466. <annotation name="@export_global_file" qualifiers="vararg">
  467. <return type="void" />
  468. <param index="0" name="filter" type="String" default="&quot;&quot;" />
  469. <description>
  470. Export a [String] 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.
  471. If [param filter] is provided, only matching files will be available for picking.
  472. See also [constant PROPERTY_HINT_GLOBAL_FILE].
  473. [codeblock]
  474. @export_global_file var sound_effect_path: String
  475. @export_global_file("*.txt") var notes_path: String
  476. [/codeblock]
  477. </description>
  478. </annotation>
  479. <annotation name="@export_group">
  480. <return type="void" />
  481. <param index="0" name="name" type="String" />
  482. <param index="1" name="prefix" type="String" default="&quot;&quot;" />
  483. <description>
  484. 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.
  485. 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].
  486. Groups cannot be nested, use [annotation @export_subgroup] to add subgroups within groups.
  487. See also [constant PROPERTY_USAGE_GROUP].
  488. [codeblock]
  489. @export_group("Racer Properties")
  490. @export var nickname = "Nick"
  491. @export var age = 26
  492. @export_group("Car Properties", "car_")
  493. @export var car_label = "Speedy"
  494. @export var car_number = 3
  495. @export_group("", "")
  496. @export var ungrouped_number = 3
  497. [/codeblock]
  498. </description>
  499. </annotation>
  500. <annotation name="@export_multiline">
  501. <return type="void" />
  502. <description>
  503. Export a [String] 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.
  504. See also [constant PROPERTY_HINT_MULTILINE_TEXT].
  505. [codeblock]
  506. @export_multiline var character_biography
  507. [/codeblock]
  508. </description>
  509. </annotation>
  510. <annotation name="@export_node_path" qualifiers="vararg">
  511. <return type="void" />
  512. <param index="0" name="type" type="String" default="&quot;&quot;" />
  513. <description>
  514. Export a [NodePath] property with a filter for allowed node types.
  515. See also [constant PROPERTY_HINT_NODE_PATH_VALID_TYPES].
  516. [codeblock]
  517. @export_node_path("Button", "TouchScreenButton") var some_button
  518. [/codeblock]
  519. </description>
  520. </annotation>
  521. <annotation name="@export_placeholder">
  522. <return type="void" />
  523. <param index="0" name="placeholder" type="String" />
  524. <description>
  525. Export a [String] property with a placeholder text displayed in the editor widget when no value is present.
  526. See also [constant PROPERTY_HINT_PLACEHOLDER_TEXT].
  527. [codeblock]
  528. @export_placeholder("Name in lowercase") var character_id: String
  529. [/codeblock]
  530. </description>
  531. </annotation>
  532. <annotation name="@export_range" qualifiers="vararg">
  533. <return type="void" />
  534. <param index="0" name="min" type="float" />
  535. <param index="1" name="max" type="float" />
  536. <param index="2" name="step" type="float" default="1.0" />
  537. <param index="3" name="extra_hints" type="String" default="&quot;&quot;" />
  538. <description>
  539. Export an [int] or [float] 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 [code]EditorSettings.interface/inspector/default_float_step[/code] setting.
  540. 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.
  541. Hints also allow to indicate the units for the edited value. Using [code]"radians"[/code] you can specify that the actual value is in radians, but should be displayed in degrees in the Inspector dock. [code]"degrees"[/code] allows to add a degree sign as a unit suffix. Finally, a custom suffix can be provided using [code]"suffix:unit"[/code], where "unit" can be any string.
  542. See also [constant PROPERTY_HINT_RANGE].
  543. [codeblock]
  544. @export_range(0, 20) var number
  545. @export_range(-10, 20) var number
  546. @export_range(-10, 20, 0.2) var number: float
  547. @export_range(0, 100, 1, "or_greater") var power_percent
  548. @export_range(0, 100, 1, "or_greater", "or_less") var health_delta
  549. @export_range(-3.14, 3.14, 0.001, "radians") var angle_radians
  550. @export_range(0, 360, 1, "degrees") var angle_degrees
  551. @export_range(-8, 8, 2, "suffix:px") var target_offset
  552. [/codeblock]
  553. </description>
  554. </annotation>
  555. <annotation name="@export_subgroup">
  556. <return type="void" />
  557. <param index="0" name="name" type="String" />
  558. <param index="1" name="prefix" type="String" default="&quot;&quot;" />
  559. <description>
  560. 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].
  561. See also [constant PROPERTY_USAGE_SUBGROUP].
  562. [codeblock]
  563. @export_group("Racer Properties")
  564. @export var nickname = "Nick"
  565. @export var age = 26
  566. @export_subgroup("Car Properties", "car_")
  567. @export var car_label = "Speedy"
  568. @export var car_number = 3
  569. [/codeblock]
  570. [b]Note:[/b] Subgroups cannot be nested, they only provide one extra level of depth. Just like the next group ends the previous group, so do the subsequent subgroups.
  571. </description>
  572. </annotation>
  573. <annotation name="@icon">
  574. <return type="void" />
  575. <param index="0" name="icon_path" type="String" />
  576. <description>
  577. Add a custom icon to the current script. The script must be registered as a global class using the [code]class_name[/code] keyword for this to have a visible effect. 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.
  578. [codeblock]
  579. @icon("res://path/to/class/icon.svg")
  580. [/codeblock]
  581. [b]Note:[/b] Only the script can have a custom icon. Inner classes are not supported.
  582. [b]Note:[/b] As annotations describe their subject, the [code]@icon[/code] annotation must be placed before the class definition and inheritance.
  583. [b]Note:[/b] Unlike other annotations, the argument of the [code]@icon[/code] annotation must be a string literal (constant expressions are not supported).
  584. </description>
  585. </annotation>
  586. <annotation name="@onready">
  587. <return type="void" />
  588. <description>
  589. 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].
  590. [codeblock]
  591. @onready var character_name: Label = $Label
  592. [/codeblock]
  593. </description>
  594. </annotation>
  595. <annotation name="@rpc" qualifiers="vararg">
  596. <return type="void" />
  597. <param index="0" name="mode" type="String" default="&quot;authority&quot;" />
  598. <param index="1" name="sync" type="String" default="&quot;call_remote&quot;" />
  599. <param index="2" name="transfer_mode" type="String" default="&quot;unreliable&quot;" />
  600. <param index="3" name="transfer_channel" type="int" default="0" />
  601. <description>
  602. Mark the following method for remote procedure calls. See [url=$DOCS_URL/tutorials/networking/high_level_multiplayer.html]High-level multiplayer[/url].
  603. The order of [code]mode[/code], [code]sync[/code] and [code]transfer_mode[/code] does not matter and all arguments can be omitted, but [code]transfer_channel[/code] always has to be the last argument. The accepted values for [code]mode[/code] are [code]"any_peer"[/code] or [code]"authority"[/code], for [code]sync[/code] are [code]"call_remote"[/code] or [code]"call_local"[/code] and for [code]transfer_mode[/code] are [code]"unreliable"[/code], [code]"unreliable_ordered"[/code] or [code]"reliable"[/code].
  604. [codeblock]
  605. @rpc
  606. func fn(): pass
  607. @rpc("any_peer", "unreliable_ordered")
  608. func fn_update_pos(): pass
  609. @rpc("authority", "call_remote", "unreliable", 0) # Equivalent to @rpc
  610. func fn_default(): pass
  611. [/codeblock]
  612. </description>
  613. </annotation>
  614. <annotation name="@tool">
  615. <return type="void" />
  616. <description>
  617. 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].
  618. [codeblock]
  619. @tool
  620. extends Node
  621. [/codeblock]
  622. [b]Note:[/b] As annotations describe their subject, the [code]@tool[/code] annotation must be placed before the class definition and inheritance.
  623. </description>
  624. </annotation>
  625. <annotation name="@warning_ignore" qualifiers="vararg">
  626. <return type="void" />
  627. <param index="0" name="warning" type="String" />
  628. <description>
  629. Mark the following statement to ignore the specified [param warning]. See [url=$DOCS_URL/tutorials/scripting/gdscript/warning_system.html]GDScript warning system[/url].
  630. [codeblock]
  631. func test():
  632. print("hello")
  633. return
  634. @warning_ignore("unreachable_code")
  635. print("unreachable")
  636. [/codeblock]
  637. </description>
  638. </annotation>
  639. </annotations>
  640. </class>