Exports without GDScript (2023)

Introduction to exports

In Godot, class members can be exported. This means that their values ​​are saved along with the resource (e.g. thecena) to which they are linked. They will also be available for editing in the property editor. The export is done using the keywordexport:

extends Buttonexport era number = 5 # The value will be saved and visible in the property editor.

An exported variable must be initialized by a constant expression or have an export inference in the form of a keyword argumentexport(see section belowexamples).

One of the main benefits of exporting member variables is making them visible and editable in the editor. In this way, artists and game designers can modify values ​​that influence how the program works. For this, there is a special export syntax.

To use

Property export can also be done in other languages ​​such as C#. The syntax varies by language.


# If the exported value assigns a constant or constant expression,# the type will be inferred and used in the editor.export era number = 5# The export can take a basic data type as an argument, which will be# used in the editor.export(E T) era number# The export can also take a resource type to use as a tooltip.export(Texture) era face_of_characterexport(crowded scene) era scene_file# There are many types of resources that can be used this way, try for example# or follow to enumerate them:export(Resource) era resource# Integers and strings suggest enumerated values.# The editor will enumerate as 0, 1 and 2.export(E T, "Warrior", "Seco", "Burglar") era character_class# The editor will enumerate with string names.export(Chain, "Rebeca", "María", "Read") era Character's Name# named enumeration values# The editor will enumerate as THING_1, THING_2, ELSE_THING.enumeration NamedEnum {WHAT 1, WHAT_2, ANOTHER THING = -1}export(NamedEnum) era x# strings as paths# String is a path to a file.export(Chain, FILE) era F# String is a path to a directory.export(Chain, ADDRESS) era F# String is a path to a file, a custom filter is provided as a hint.export(Chain, FILE, "*.TXT") era F# It is also possible to use paths in the global file system,# but only in "tool" mode scripts.# String is a path to a PNG file on the global file system.export(Chain, FILE, GLOBAL, "*.png") era image_tool# String is a path to a directory on the global file system.export(Chain, ADDRESS, GLOBAL) era tool_dir# The MULTILINE setting tells the editor to display a large input# field to edit on multiple lines.export(Chain, MULTILINE) era text# Limiting editor input ranges# Allow integer values ​​from 0 to 20.export(E T, 20) era eu# Allow integer values ​​from -10 to 20.export(E T, -10, 20) era j# Allow fluctuations from -10 to 20 and set the value to multiples of 0.2.export(float, -10, 20, 0,2) era k# Allow values ​​'y = exp(x)' where 'y' varies between 100 and 1000# while adjusting in steps of 20. The editor will display a# slider to easily edit the value.export(float, Exp, 100, 1000, 20) era you# Floats with relaxation track# Show a visual representation of the 'ease()' function# when editing.export(float, EASE) era transition speed# Cores# Color given as red-green-blue value (alpha will always be 1).export(Cor, RGB) era column# Color given as red-green-blue-alpha value.export(Cor, RGBA) era column# us# Another node in the scene can be exported as a NodePath.export(NodePath) era node_path# Note that the node itself is not being exported -# there is one more step to call node true:a list era It = get_node(node_path)# Resourcesexport(Resource) era resource# In Inspector you can drag and drop a resource file# from dock to file system in variable slot.# Opening the inspector dropdown may result in a# extremely long list of possible classes to create, however.# So if you specify a resource extension like:export(NodoAnimation) era resource# The dropdown will be limited to AnimationNode and all# your inherited classes.

Note that even if the script is not run while in the editor, the exported properties can still be edited. This can be used in conjunction with ascript in "tool" mode.

Bit Mark Export

Integers used as flags can store multiple valuesTRUE/FALSE(Booleans) in a property. Using export inferenceE T FLAGS, ..., can be configured in the editor:

# Set any of the provided flags in the editor.export(E T, FLAGS, "Fogo", "Water", "Terra", "Vento") era spell_elements = 0

You must provide a string description for each indicator. In this example,fogohas value 1,aguahas value 2,Terrahas value 4 andVentocorresponds to the value 8. Normally, constants should be defined accordingly (for example,constant ELEMENT_WIND = 8etc).

Export inferences are also provided for physical and rendering layers defined in project settings:

export(E T, 2D_LAYERS_PHYSICS) era physical_2d_layersexport(E T, LAYERS_2D_RENDER) era layers_2d_renderexport(E T, 3D_LAYERS_PHYSICS) era physical_3d_layersexport(E T, LAYERS_3D_RENDER) era layers_3d_render

Using bitwise flags requires some knowledge of bitwise operations. When in doubt, export boolean variables.

export matrices

Exported arrays can have initializers, but they must be constant expressions.

If the exported array specifies an inherited type of Resource, the array values ​​can be set in the inspector by dragging and dropping multiple files from the Files panel at once.

# The default value must be a constant expression.export era a = [1, 2, 3]# Exported arrays can specify type (using the same hints as before).export(Training, E T) era Appetizer = [1, 2, 3]export(Training, E T, "Rojo", "verde", "Azul") era enumerations = [2, 1, 0]export(Training, Training, float) era two-dimensional = [[1,0, 2.0], [3.0, 4.0]]# You can omit the default value, but it will be null if not assigned.export(Training) era bexport(Training, crowded scene) era prices# Arrays with specific types that inherit from the resource can be defined using# drag and drop multiple files from the file system.export(Training, Texture) era texturesexport(Training, crowded scene) era prices# Typed arrays work too, just initialize empty:export era vetor3s = GroupVetor3Array()export era string instruments = PoolStringArray()# The pattern can include runtime values, but not# be exported.era C = [a, 2, 3]

Defining variables exported from a tool script

When changing the value of a variable exported from a script intool mode, the inspector value will not update automatically. To update the callchange_list_property_notify ()after setting the value of the exported variable.

advanced exports

Not all export types can be provided at the same language level to avoid unnecessary design complexity. The following describes more or less some common export functions that can be implemented with a low-level API.

Before reading further, you should familiarize yourself with how properties are handled and how they can be customized with methods._to place(),_get(), eu_get_property_list()as described inAccess an object's data or logic.

See too

For binding properties using the above methods in C++, seeProperty binding using _set/_get/_get_property_list.


The script must operate ontoolso the above methods can work inside the editor.


To understand how to best use the sections below, you need to understand how to create properties with advanced exports.

Function _get_property_list(): era properties = [] # Same as "export(int) var my_property" properties.attach({ name = "my property", type = TYPE_INT }) give back properties
  • He_get_property_list()The function is called by the inspector. You can override it for more advanced exports. You must return aTrainingwith the content of the properties for the function to work.

  • nameis the name of a category to be added to the inspector

  • typeis the property type ofVariant.Type.

To use

Hefloattype is called real(REAL_TYPE) noVariant.Typeenumeration

Attach variables to properties

To attach variables to properties (allowing the property's value to be used in scripts), you must create a variable with exactly the same name as the property, or you may need to override the_to place()y_get()methods. Attaching a variable to a property also gives you the ability to assign a default state to it.

# This variable is determined by the following function.# This variable acts like a normal gdscript export.era my property = 5Function _get_property_list(): era properties = [] # Same as "export(int) var my_property" properties.attach({ name = "my property", type = TYPE_INT }) give back properties

Adding default values ​​to properties

To set defaults for advanced exports, you must override theproperty_can_revert()ypropiedad_get_revert()methods.

  • Heproperty_can_revert()The method takes the name of a property and must returnTRUEwhether the property can be reversed. This will activate the Revert button next to the property in the inspector.

  • Hepropiedad_get_revert()The method receives the name of a property and must return the default value of that property.

Function _get_property_list(): era properties = [] properties.attach({ name = "my property", type = TYPE_INT }) give back propertiesFunction property_can_revert(property): e property == "my property": give back TRUE give back FALSEFunction propiedad_get_revert(property): e property == "my property": give back 5

Adding script categories

For better visual distinction of properties, a special script category can be added to the inspector to act as a separator.Variables of Road mapare an example of a built-in category.

Function _get_property_list(): era properties = [] properties.attach({ name = "Debug", type = NIL_TYPE, use = PROPERTY_USE_CATEGORY | PROPERTY_USE_SCRIPT_VARIABLE }) # Example of how to add a property to the script category properties.attach({ name = "logging_enabled", type = TYPE_BOOL }) give back properties
  • nameis the name of a category to be added to the inspector;

  • Each subsequent property added after the category definition will be part of the category.

  • PROPERTY_USE_CATEGORYindicates that the property is to be treated specifically as a script category, so the typeNIL_TYPEit can be ignored as it won't actually be used for scripting logic, but it should be set anyway.

grouping properties

A list of properties with similar names can be grouped together.

Function _get_property_list(): era properties = [] properties.attach({ name = "rotate", type = NIL_TYPE, track_chain = "rotate_", use = PROPERTY_USE_GROUP | PROPERTY_USE_SCRIPT_VARIABLE }) # Example of adding to the group properties.attach({ name = "rotate_speed", type = REAL_TYPE }) # This property will not be added to the group # because it doesn't have the "rotate_" prefix. properties.attach({ name = "route_color", type = COLOR_TYPE }) give back properties
  • nameis the name of a group to be displayed as a collapsible list of properties;

  • Each next property added after the group property with the prefix (determined bytrack_chain) will be shortened. For example,speed_routewill be shortened tospeedin this case. Although,movement speedwill not be part of the group and will not be abbreviated.

  • PROPERTY_USE_GROUPindicates that the property is to be treated specifically as a group of scripts, so the typeNIL_TYPEit can be ignored as it won't actually be used for scripting logic, but it should be set anyway.


Top Articles
Latest Posts
Article information

Author: Foster Heidenreich CPA

Last Updated: 01/11/2023

Views: 5390

Rating: 4.6 / 5 (56 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.