Hi. I used to code many years ago and I used to program everything in code to make applications/games work. Now, after having been looking at Godot (4.4.1) for a little while I've noticed this feature whereby you can apparently export variables to make them 'editable' in the inspector. I thought that all games would be based upon or designed from actual script code only. I've been trying to understand what the purpose of exporting of variables is or why it would be needed. Please would someone be kind enough to explain the concept of exporting variables and, if possible, provide a very basic project demonstrating the idea behind it all.
Thank you in advance for any help given.
Exporting variables
MrWWW Some purposes: customizing different instances of the same scene, populating data fields of a custom resource objects, easy parameter tweaking for team members that don't code, tweaking at runtime in the inspector, easy assignment of node references without needing to deal with path strings...
- Edited
Another purpose: An excuse to add images or animations to tutorials.
Personally, I seldom use Export variables. I try to do everything in the script code, because I think it's more reliable and easier to document.
However, when I'm experimenting with features or prototyping a new project, I may use them temporarily.
Here's an instance where Export variables were useful. It's code that runs in the Godot editor and tests a Godot add-on. Using Export variables avoids the need for the user to modify the script when changing the variables dir_readable
and dir_writable
:
https://github.com/daveTheOldCoder/Godot3To4FileConversion#test
The scripts that use the Export variables are test/CreateTestFilesGodot3/main.gd
and test/ValidateTestFilesGodot4/main.gd
.
Here's a simple example. In my world map I have different locations with many variables as export variables. Why? I want to be able to click the location in the editor and instantly make changes to it. The alternative would either be having all that information in code somewhere or reading and parsing some CSV document with all the relevant data. Using the export variables lets me iterate faster cause I have the data closer to how the player will discover it.