Exposing a certain script or resource in exported builds

Godot Version

Godot 4.3

Question

I am looking for a way to export a certain script or resource (in my case containing player movement variables for a 2D platformer) alongside the normal executable.

A user should be able to change stuff in this exposed file, which is then read by the executable.

I want to do this because I want people to be able to play with the movement variables for the player character, without sending them my project file.

Is something like this possible?

1 Like

You could export/copy the script and load it onto the place dynamically, but you could also expose a few variables easily with some UI sliders/spin boxes.

The easiest no-code way to easily modify the game is to export by zip, which can be easily unpacked, edited, and re-packed by users.

1 Like

Thanks for taking the time to reply!

I have a debug UI, but I have like 60 movement variables (for different player movement mechanics) and no save system yet, I thought maybe there is an easy way just to expose the player movement resource, just how one might expose a save data file for external editing.

I don’t want to share anything besides an executable and this resource, and make it easy for them just to jump into a code editor to tweak the variables.

1 Like

You could have a base node with a script that uses FileAccess (or something else like ResourceLoader, or a plugin) to load the script (maybe put it in the same folder and use a relative set file path). Then, use Object.set_script() to set the script of the object to be the new script. Then the user can edit the script, which will be loaded (if put in the right place) and run. This does cause security issues if people are sharing it, or it’s online gameplay, as anyone could make the code run anything, which could include malware.

3 Likes

Thank you for your proposed solution as well as the warnings!
I will try your solution and update the post if it works.

1 Like