1
\$\begingroup\$

I'm trying to debug an issue with my game, where the function that should be connected to a signal is not being called. I have a created minimal repro of the situation by:

  1. Create a fresh Godot 4 project

  2. Create a Thing scene with StaticBody2D node (with sprite and square collision shape) and a Thing.gd script:

    extends StaticBody2D
    
    func _on_input_event(viewport, event, shape_idx):
        if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
          modulate = Color(1,1,0,1) if event.is_pressed() else Color(1,1,1,1)
    

    The _on_input_event function is connected to the input_event signal of the StaticBody2D.

  3. Creating a Root Node2D node with a Root.gd script:

    extends Node2D
    
    var thing_scene = preload("res://Thing.tscn")
    
    func _ready():
        var other_thing = thing_scene.instantiate()
        other_thing.position = Vector2(200, 200)
        add_child(other_thing)
    
  4. Set a break point at that last line of code

  5. Run the Root node in debug mode

  6. When the breakpoint hits, click "Locals" => "other_thing"'s Object ID to open the Inspector

At this point I can see the properties of the Node, like so:

Godot editor in debug mode showing the Inspector window highlighted

My problem is that I see nothing if I then click on the "Node" tab next to "Inspector", it will just say:

Select a single node to edit its signals and groups

Here's a screenshot of that:

Godot editor in debug mode showing quote from above

What I was hoping to see is the same thing I see when not running in Debug mode and selecting the to-be-instantiated scene's StaticBody2D node:

Godot editor in edit mode showing the connected signals

In my sample / repro above the signal is working because I can observe the function's effects. In my actual game the signal is not working, which is why I'm looking for a way to debug that situation. I want to know if the signal is connected at all, or if something else is causing my issues.

Bottom line: How can I check connected signals for a component created with instantiate() while debugging?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I'm unaware of a way to see the connected signals of a Object in runtime in the debugger.

You could select the Node in the "Scene" in the "Local" tab while the game is running, but that will only show you the signals connected in design. I mean, it is not looking at the Nodes in runtime. You can see at the Nodes in runtime using the "Remote" tab, but then it won't show the signals.


Instead, we could check the connections form code. To see what is connected to an Object do this:

for signal_description in signal_source.get_signal_list():
    var signal_name := str(signal_description["name"])
    var connections := signal_source.get_signal_connection_list(signal_name)
    for connection in connections:
        prints(connection)

Or to see what is connected to an Object do this:

for connections in signal_target.get_incoming_connections():
    for connection in connections:
        prints(connection)

Regardless, about the issue you are trying to debug… You don't need to connect the "input_event" signal from the StaticBody2D to itself, instead you can override the virtual method _input_event.


Finally, about the source of your issue… Following your instructions you didn't set input_pickable to true. It defaults to false in Godot 4.

You need to set input_pickable to true for either the "input_event" signal or the virtual method _input_event to work. Addendum: Inside of a Viewport (either SubViewport or Window) you also need to set physics_object_picking to true.

This is likely the source of the issue.

Note: "input_event" and _input_event also don't work if the collision_layer property is empty (i.e. 0 - it defaults to 1).


By the way, be aware that, based on your first picture, you have added an instance of Thing in Root in the editor. And you are also adding another instance of Thing from the code in _ready. So there will be two instances in runtime.

You also want to make sure the positions and dimensions of the collision shape are what you expect. You can enable "Visible Collision Shapes" in the "Debug" menu so Godot renders the collision shapes in the running game.

\$\endgroup\$
2
  • \$\begingroup\$ Cheers! PS. I suggest tweaking the snippets, first one to prints(connection) (without ...s), and second one to for key in connections: and prints(key, "=>", connections[key]). Either way, they got me in the right direction and answer the question I asked! \$\endgroup\$
    – Jeroen
    Mar 21, 2023 at 16:33
  • \$\begingroup\$ All the other tips are once again educational and helpful! Some of them were part of the problem, and for future visitors additionally you may have (like I did) a SubViewport in the mix which needs Physics => Objects Picking also turned on for all of it to work. \$\endgroup\$
    – Jeroen
    Mar 21, 2023 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .