File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
tutorials/scripting/gdscript Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -542,6 +542,36 @@ automatically. To update it, call
542542:ref: `notify_property_list_changed() <class_Object_method_notify_property_list_changed >`
543543after setting the exported variable's value.
544544
545+ Reading an exported variable's value early on
546+ ---------------------------------------------
547+
548+ If you read an exported variable's value in :ref: `_init() <class_Object_private_method__init >`,
549+ it will return the default value specified in the export annotation instead of the value
550+ that was set in the inspector. This is because the inspector only sets the value after
551+ the object is constructed. To get the value set in the inspector, you need
552+ to read it *after * the object is constructed, such as in
553+ :ref: `Node._ready() <class_Node_method_ready >`. You can also read the value in a
554+ setter that's defined on the exported property, which is useful in custom resources
555+ where ``_ready() `` is not available:
556+
557+ ::
558+
559+ # Set this property to 3 in the inspector.
560+ @export var exported_variable = 2:
561+ set(value):
562+ exported_variable = value
563+ print("Inspector-set value: ", exported_variable)
564+
565+ func _init():
566+ print("Initial value: ", exported_variable)
567+
568+ Results in:
569+
570+ .. code-block :: none
571+
572+ Initial value: 2
573+ Inspector-set value: 3
574+
545575 Advanced exports
546576----------------
547577
You can’t perform that action at this time.
0 commit comments