this post was submitted on 03 Jul 2023
10 points (100.0% liked)

Godot

5894 readers
34 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

[email protected]

Credits

founded 1 year ago
MODERATORS
 

Hi everyone, first time posting here. I was going to go to Discord but thought it's better to ask somewhere that can turn up on search engines for future confused game devs.

I've got a parameterised signal listener like this:

func _on_movement_to_exit_complete(character: Node2D):
	var f = func():
		print("_on_movement_to_exit_complete: "+str(character))
		var dungeon_tilemap: TileMap = dungeon_control.get_current_dungeon_tilemap()
		var party = dungeon_tilemap.get_node("Party")
		var initial_party = dungeon_control.get_parent().get_node("InitialParty")

		party.remove_child(character)
		initial_party.add_child(character)

		if party.get_child_count() == 0:
			for party_member in initial_party.get_children():
				var tilemap_movement: TilemapMovement = party_member.get_node("TilemapMovement")
				print("Disconnecting movement finished listener for "+str(party_member))
				tilemap_movement.disconnect("movement_finished", _on_movement_to_exit_complete(character))

			load_next_level()

	return f

Basically, if all the party members have exited the level (and been removed from the 'party' node) I want to disconnect this movement_finished signal from _on_movement_to_exit_complete. But when I try this I get an error:

E 0:00:07:0777   GameControl.gd:80 @ <anonymous lambda>(): Disconnecting nonexistent signal 'movement_finished', callable: <anonymous lambda>(lambda).
  <C++ Error>    Condition "!s->slot_map.has(*p_callable.get_base_comparator())" is true.
  <C++ Source>   core/object/object.cpp:1331 @ _disconnect()
  <Stack Trace>  GameControl.gd:80 @ <anonymous lambda>()
                 TilemapMovement.gd:23 @ _on_animation_finished()

Why doesn't it think movement_finished exists? Is there something wrong with disconnecting signals from inside their listeners? And is there another way of doing this? (Maybe something like a signal that fires once then disconnects?)

This is in Godot 4 by the way.

Also, is there a way to make the posting box wider in the programming.dev web frontend? It's really hard to work with pasted code here!

top 4 comments
sorted by: hot top controversial new old
[โ€“] [email protected] 5 points 1 year ago* (last edited 1 year ago) (1 children)

(Maybe something like a signal that fires once then disconnects?)

Im not sure if this is exactly what you mean or if im telling you things you already know ๐Ÿ˜…, but yes, you can mark signals as "Oneshot" where they disconnect themselves after firing once in the advanced options in the signal connect menu.

Or alternatively if you connect them via code you can use the corresponding flag CONNECT_ONE_SHOT in the connect function

[โ€“] [email protected] 1 points 1 year ago* (last edited 1 year ago)

Thanks, that's exactly what I was looking for!

[โ€“] [email protected] 1 points 1 year ago

I think you've already found a better way, but I'll answer your original question too.

You mention that the party members have been removed from the party node. I believe signals are tied to a node, so as soon as they're freed or otherwise removed, that signal listener is already disconnected. Hence the error you're getting.

[โ€“] [email protected] 1 points 1 year ago

Where is the definition of your signal? Would be best to compare that with your usage-site.

Also, in Godot 4 you don't have to reference signals as strings, they exist as properties on your class. You should be able to reference the signal as i.e. TilemapMovement.movement_finished.connect(...)

load more comments
view more: next โ€บ