The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Hi forum,

When my program tries to emit a signal it gives the following errors. Any ideas why?

call: Can't call non-static function '_on_signal' in script.
emit_signal: Error calling method from signal 'the_signal'


I have two scripts, call them primary and secondary. In primary I connect a signal the_signal to a function in secondary by

var secondary = load("res://")
signal the_signal()

func _ready():
    self.connect("the_signal", secondary, "_on_signal" )

and in secondary I have the receiving function

func _on_signal():
    # doing some stuff
in Engine by (141 points)
edited by

2 Answers

+3 votes
Best answer

Because a non-static function always refers to a particular instance. However, in your case there's no such instance! So either make the function static...


static func _on_signal():
    print("It works!")

... or create an actual instance of the script with new():


var secondary = load("res://").new()
signal the_signal

func _ready():
    self.connect("the_signal", secondary, "_on_signal" )
    secondary.test = 2


var test = 1

func _on_signal():
    print("Test: %d" % test)
by (10,634 points)
selected by

Worked like a charm =)

0 votes

There's another way this can happen i think. if you accidently refer to a script when connecting signals instead of a node. the two are separate.

by (65 points)
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.