Skip to content

Commit 3439a19

Browse files
authored
Merge pull request #9026 from dalexeev/gds-export-storage
GDScript: Document `@export_storage` annotation
2 parents 0f3f7a1 + 88ec4c2 commit 3439a19

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

tutorials/scripting/gdscript/gdscript_exports.rst

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,28 @@ Packed type arrays also work, but only initialized empty:
368368
@export var vector3s = PackedVector3Array()
369369
@export var strings = PackedStringArray()
370370

371+
``@export_storage``
372+
-------------------
373+
374+
By default, exporting a property has two effects:
375+
376+
1. makes the property stored in the scene/resource file (:ref:`PROPERTY_USAGE_STORAGE <class_@GlobalScope_constant_PROPERTY_USAGE_STORAGE>`);
377+
2. adds a field to the Inspector (:ref:`PROPERTY_USAGE_EDITOR <class_@GlobalScope_constant_PROPERTY_USAGE_EDITOR>`).
378+
379+
However, sometimes you may want to make a property serializable, but not display it
380+
in the editor to prevent unintentional changes and cluttering the interface.
381+
382+
To do this you can use :ref:`@export_storage <class_@GDScript_annotation_@export_storage>`.
383+
This can be useful for :ref:`@tool <class_@GDScript_annotation_@tool>` scripts.
384+
Also the property value is copied when :ref:`Resource.duplicate() <class_Resource_method_duplicate>`
385+
or :ref:`Node.duplicate() <class_Node_method_duplicate>` is called, unlike non-exported variables.
386+
387+
::
388+
389+
var a # Not stored in the file, not displayed in the editor.
390+
@export_storage var b # Stored in the file, not displayed in the editor.
391+
@export var c: int # Stored in the file, displayed in the editor.
392+
371393
Setting exported variables from a tool script
372394
---------------------------------------------
373395

@@ -394,5 +416,5 @@ described in :ref:`doc_accessing_data_or_logic_from_object`.
394416
.. seealso:: For binding properties using the above methods in C++, see
395417
:ref:`doc_binding_properties_using_set_get_property_list`.
396418

397-
.. warning:: The script must operate in the ``tool`` mode so the above methods
419+
.. warning:: The script must operate in the ``@tool`` mode so the above methods
398420
can work from within the editor.

0 commit comments

Comments
 (0)