Mouse event not detected when scene added instanced through code

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

My game has some point and click mechanics, where I have a sprite containing an image and parts of that image are clickable, with clicks being detected through a KinematicBody2D with a collision shape. When I play scene, the clicks are detected correctly. However, when I instance this scene from another scene through code, the clicks are not detected.

My scene layout is like this:

ClickableSceneUI: (Contains ClickableScene, which contains the sprite setup mentioned above)

Control1
--Button
--Control2
----ClickableScene

ClickableScene:

Sprite
--KinematicBody2D
----CollisionPolygon2D

Where ClickableScene has code

func _on_ClickSprite_input_event(_viewport, event, _shape_idx):
	if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT:
		emit_signal("click_emit",event.position)

I have another scene MainGame, where in the script MainGame.gd I load ClickableSceneUI with the following code:

var clickableSceneUI = load(path).instance()
get_tree().get_root().call_deferred("add_child", clickableSceneUI )

Both Control1 and Control2 in ClickableSceneUI has mouse filters set to Ignore. As mentioned, when I click “Play Scene” to directly play ClickableSceneUI, everything works. But when I load ClickableSceneUI from MainGame, the clicks are not detected in ClickableScene. ClickableSceneUI’s button, however, can be clicked.

Anyone have any idea why this is happening and how to fix it?

:bust_in_silhouette: Reply From: rhyzue

Never mind, I’ll just use a TextureButton. Why didn’t I do that before? facepalm

(No idea why, but Button, TextureButton clicks can be detected while my kinematicBody/collisionPolygon fails)