Can you load new (user-generated) code at runtime?

Godot Version

Godot 4.2

Question

i’m a teacher and long ago made a game to teach my kids to code. They wrote AI scripts and the game would load them at runtime and have the AIs fight.

i don’t think most engines support that (it’s not very safe) but i thought i’d ask - can a Godot executable read a GDScript file at runtime and execute it?

If it matters, the scripts my students used had to inherit from a specific class and override a specific method. The script didn’t draw anything. It was given a list of choices (in my case, a list of enemies they could attack) and had to return which of those choices it selected.

You can load GDScript at runtime yes, you can either load it as a file or just set the source of the GDScript itself with source and then use reload

1 Like