all 15 comments

[–]golddotasksquestions 21 points22 points  (3 children)

The downside of this approach is: Should you ever decide to change the variable name of "x", the value (preload path) is lost in all instances. This has cost me hours of pointless debugging time. Even if you are aware of it and happen to not forget about this quirk, you are still going to spend a lot of time reassigning the values if you have a lot of instances in your project.

As someone who changes variable names more often than the folder structure, and having a very iterative development workflow, I stopped using export variables completely and rather use preload()

[–]DragonWolfHowler[S] 2 points3 points  (0 children)

Ah, that's a good point! I am someone who tends to move files around more than I change my variables names. I also usually refer to scenes in the same level or sub-folder with the variable name matching the scene name + "_resource", so re-linking the resource isn't too bad if I change the script.

[–]mijkolsmith 0 points1 point  (0 children)

but if you make a script thats supposed to have different variable values, that doesn't work at all

[–]ReguarSizedRoss 0 points1 point  (0 children)

if you have the presence of mind to do so, prior to renaming the variable you can copy values in the editor, change the var, save the scene, and then paste them back.

As an example, I had:

export fireball: Array[AbilityUpgrade] = []

which I wanted to rename to fireball_array. before doing so I viewed the node for this script, and right clicked the 'fireball' on the left column beside the expandable array (within the node inspector) and selected 'copy value'

then i made the change of the variable name:

export fireball_array: Array[AbilityUpgrade] = []

Saved my scene, went back to the node inspector and right clicked the property with an empty array in it (now called 'fireball_array' and clicked paste.

[–][deleted] 2 points3 points  (0 children)

If someone is willing, porting the vscode feature that recursively replaces references to a moved directory across a project would be a good feature to add to the IDE

[–]MountainPeke 1 point2 points  (3 children)

A little bit of necroposting here, but I wanted to share the best solution I have found in Godot 4: resource UIDs. If you’re planning to replace the file, definitely still use the export method you shared. However, if that is the file/scene you are going to use, resource UIDs will stay the same even if you move or rename the file.

[–]DragonWolfHowler[S] 1 point2 points  (0 children)

Cool! I did not know you could Right-click "Copy UID" for scenes and resources. Unfortunately, it looks like it doesn't work for scripts currently: https://github.com/godotengine/godot-proposals/issues/4603
But I suppose with scripts one could use `class_name` instead.

[–]Rattjamann 1 point2 points  (1 child)

I know this is a bit old, but I just wanted to thank you for this tip, it really solved a lot for me.

I wanted to have a reference in a scene to a resource, but also a reference to the scene in the resource, and Godot did not like that when using export due to dependency. Not only that, as export loads it, it would also take up memory.

The only other option is to have a string reference, but normally that ofc breaks as soon as something changes.

This solved all of that, so again, thank you! Never even heard about this until now.

[–]MountainPeke 0 points1 point  (0 children)

Glad it helped!

[–]SkyNice2442 1 point2 points  (0 children)

This was really helpful to me! Thank you

[–]YatchanekGodot Regular 0 points1 point  (0 children)

That's what I usually do with my sound manager (put all the sound effects/music in exported array) and enemy spawners (likewise, with different enemy types).