I can't tell why my signal isn't working. I wonder if it has anything to do with the fact that I'm defining a class in the script, and creating instances with new()
or if it's because the signal is in the same script from where it's called, since the entire script is in one file (except for one variable in an autoload script) associated to one scene.
I'm creating the signal solely through code.
The full error message is: In Object of type 'Node2D': Attempt to connect nonexistent signal 'particle_draw' to method 'Node2D._on_particle_draw'
This is the abbreviated script, where the signal is created and used:
extends Node2D
# isn't working with or without the argument in this line
signal particle_draw # (particles) # <-- declare
func _input(event):
# create a BloodParticleSystem on mouse click
if event.is_action_pressed("click"):
var bps = BloodParticleSystem.new()
add_child(bps)
bps.set_global_pos( get_viewport().get_mouse_pos() )
bps.connect("particle_draw", self, "_on_particle_draw") # <-- connect
func _on_particle_draw(particles):
print ("SIGNAL WAS EMITTED")
# ... do stuff
class BloodParticleSystem extends Node2D:
var particles = []
func _fixed_process(delta):
if lifetime > 0:
# ... move particles and reduce lifetime by delta
else:
emit_signal("particle_draw", particles) # <-- emit
queue_free()