Instantiated RigidBody2D scene doesnt detect input

Godot Version

4.4.1

Question

Beginner with Godot. I have a “TriangleProjectile” scene that consists of:

  • Rigidbody2D
    • CollisionShape2D
    • Sprite2D

The Rigidbody2D has the following script attached:

extends RigidBody2D
	
func _ready():
	input_pickable = true

func _input_event(viewport, event, shape_idx):
	print("EVENT: ", event)
	if event is InputEventMouseButton and event.pressed:
		queue_free()

When I run the scene, the code works fine, but once I instantiate the scene in my MainScene, no input whatsoever is detected. I tried parenting the instances to different parents, created a “TopLayer” parent that is at the bottom of the tree (to not be blocked by anything) and tried everything I or the AI can think of, but it just doesn’t work. I’m kinda going insane here… :smiling_face_with_tear:

The instantiate code from the main script:

func spawn_triangle():
	var triangle_scene = TRIANGLE_SCENE.instantiate()
	triangle_scene.position = Vector2(200, 200)
	top_layer.add_child(triangle_scene)
	await get_tree().process_frame

I use a RigidBody2D as I want to move the object on instantiation.

Make sure that the input isn’t being consumed by a Control node by checking the tab Misc inside the Debugger dock. The field Clicked Control will show you the latest Control node that was clicked.

Another option is that you disabled the input in the game. Make sure that the Input button is pressed in the Game embedded window.

image

Thank you for your reply!
The “Game” Window is not available on my OS (MacOS), but the input button is definitely active (to clarify, its available but shows the message “Game embedding not available on your OS”)

In regards to the control node: I just have one, the GameScreen is the control node and parent for the other nodes:

When I just manually load the scene into the main scene, the object is also not clickable, is that a helpful clue maybe?

The root Control node may be eating the input events. Make sure that the root Control node Control.mouse_filter is set to Ignore then.

Why do you have a Control node as the root node of your scene?

1 Like

Omg, that was it :sob:
thank you so much for your help! I wasted so much time with that one :upside_down_face:

Picking the control node as my main was just me not knowing better, what would you suggest instead, just go with node2d instead?

I think for this scene a Node2D will do.

But the root node type depends on what your scene represents. For example, for a character that will interact with the physics system (a platformer player, an enemy,…) then a better root node would be a CharacterBody2D or RigidBody2D as these nodes interact with the physics system and let you control them. For a collectible like a coin or a heart or elements that hurt the player like spikes or poison then an Area2D would be better because this node let you know when something (a physics body or another area) enters or exits the area using its signals.

You can check the tutorial Your first 2D game in the documentation for a more information.

Thank you, that is really helpful!
I’ll give the tutorial a try :heart_hands: