+5 votes

How to I make a .gd script import another .gd script? :S
I am unable to import it even when it is in the same folder using "import "

My goal is to be able to load another script which returns the default variables depending on key :)

in Engine by (485 points)

1 Answer

+17 votes
Best answer

Use preload for other scripts, it is simple.

Like so:

const DefaultManager = preload("default_manager.gd") # Relative path
onready var default_manager = DefaultManager.new()

Note that if you want to make a static class, you might want to have a look at autoloads.

by (1,584 points)
selected by

onready var GF = preload("Scripts/GameFunctions.gd").new() Another sexier way too :D

@wombatTurkey Yeah, but I like the two-step one more. Also, in both cases it might be way simpler to use global-exposed singleton autoloads.

Yeah, I was just fooling around, love how we can chain stuff tbh

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.