+2 votes

When I create a node via GDScript it's easy, I just call for example

var test = MeshInstance.new()

But now I created a Editor Addon for a custom node called "Projectile" following this manual and I can add it via the Editor but not via Script. When I enter

var test = Projectile.new()

I get an Error

Parser Error: Identifier not found: Projectile

Is that what I'm trying to do even possible? Or do I have to use C++ for that?

in Engine by (210 points)

1 Answer

+2 votes
Best answer

I think it's not possible, but the workaround is easy:

var test = preload("res://addons/youraddon/projectile.gd").new()

You can also define it as a const to make it more readable (nice thing to note is this pattern looks like a Python import):

const Projectile = preload("res://addons/youraddon/projectile.gd")

Then you can use it like this in the rest of your script:

var test = Projectile.new()
by (28,882 points)
selected by

Thanks, it does exactly what I needed.

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 Frequently asked questions and 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 [email protected] with your username.