Cannot send Vector2 to apply_impulse through emit_signal

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bl45kc4t

I have a function connected with an emit_signal that passes in a Vector2 to use in apply_impulse

func launch(force : Vector2) -> void:

It prints the Vector2 I give it, but does not apply the impulse

However if I pass the Vector2 in by calling launch in func _ready

func _ready() -> void:

func launch(force : Vector2) -> void:

It applies the impulse and prints the Vector2

Why is apply_impulse not taking the connected signal’s Vector2?

Certainly this should be possible. You don’t show the signal wiring or how it’s being emitted, but I suspect the problem is somewhere there. Also, you mention using emit_signal, but that’s no longer valid in Godot 4 (that’s Godot 3.x).

jgodfrey | 2023-04-13 20:34

I’ve been using Godot 4.0.2 since it’s release and emit_signal does work

Cyber-Kun | 2023-04-14 07:15

Ah, yes, you’re correct. It was (and still is) a method on the Object class. Sorry for the noise…

jgodfrey | 2023-04-14 13:49

:bust_in_silhouette: Reply From: Cyber-Kun

something like this should work:

#define a signal named emitted that passes a argument force that is of type Vector2
signal emitted(force: Vector2)

#_ready function
func _ready():
#connect to the signal from self and in a lambda inside connect call a function and pass in force
	self.emitted.connect(func(force): dosomething(force))

function that is called when the signal is emitted will print force

func dosomething(force: Vector2):

keep in mind that if you never emit the signal it won’t work
you can emit the signal with:

#function to emit signal
func signal_to_emit():
#variables x and y to be passed to the signal
var x = 40
var y = 60
#emit a signal called emitted with and argument Vector2 containing x and y
emit_signal("emitted", Vector2(x, y)

hope this helps lemme know how it goes