0 votes

Im really new to Godot and have a fairly simple question that I just cant seem to wrap my head around: How to i call a function of a Script attached to an Instance?

For example:

In the Main Script of a test Project of mine there are the following lines of code:

var scene = preload("res://Ball.tscn")

func _ready():
    var test = scene.instance()

The Script attached to Ball contains the following:

func _test():

The error i get if i try to run this code is "Invalid call. Nonexistent function 'test' in base 'RigidBody2D (Ball.gd)'

Obviously there is no function called test in RigidBody2D which seems to be the error here, but then how do i refer to the Script of an Instance?

Thanks in advance for any help provided.

in Engine by (15 points)

1 Answer

+1 vote
Best answer


In your script, the function is called _test() but then you try to call it test.test(). Have you tried removing the underscore before test in your script?

by (3,505 points)
selected by

Thanks that was it, i thought you had to start every function name with an underscore because the integrated functions had them, thanks a lot :D

Your welcome!

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.