Signal not being detected by player or input on TileMap

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

I am making a farming game and spawn an instance of a crop on a TileMap into a container TileMap. I want to be able to interact with the spawned nodes (e.g., harvest). I’m currently trying signals but nothing seems to want to work.

I have a generic plant scene (Plant.tscn, and scene for the individual crops (e.g., Corn.tscn, which inherit from plant. I then instance the desired crop on a TileMap (FarmTiles.tscn, in the container (CropContainer). The script for instancing a crop is in my where I connect the signal.

extends TileMap
onready var crop_scene = preload("res://Crops/Strawberry.tscn")
    if event.is_action_pressed("Plant"):
                    var crop = crop_scene.instance()
                    var crop_x = loc.x * 16
                    var crop_y = loc.y * 16
                    crop.position.x = crop_x
                    crop.position.y = crop_y
                    crop.connect("plant_clicked", self, "_on_plant_clicked")

func _on_plant_clicked():
    	print("plant was clicked")

My plant/crop_scene’s signal (

extends Area2D
signal plant_clicked
    func _on_Plant_input_event(viewport, event, shape_idx):
    	if event.is_action_pressed("Click"):

My remote scene structure ends up looking like this after planting a couple strawberries:

        FieldTiles (TileMap)
             CropContainer (TileMap)

is crop_scene a plant script?

if so you are trying to connect the plant’s signal to its parent right? you should call connect a signal in plant script’s _ready(): function. something like connect("plant_clicked", get_parent(), "_on_plant_clicked")

asetyowatir | 2020-10-23 09:35

Thanks for the reply. I edited my original post/code so that it makes more sense. I connect the signal each time I instance the crop on my TileMap.

doogragdaba | 2020-10-23 13:32

at this line crop.connect("plant_clicked", self, "_on_plant_clicked") trs change self to get_parent() then try run again

asetyowatir | 2020-10-23 13:55

I tried that after your first comment and no luck. get_parent().get_parent() also didn’t work :confused:

doogragdaba | 2020-10-23 13:58

you should call connect in plants script, not in crop scene. like in my case TilesController spawn a Tile:

here the script in Tile:

func _ready():
	connect("input_entered", get_parent(), "_on_entered_tile", [tileIndex])
	connect("input_exited", get_parent(), "_on_exited_tile")
	alive = true

then this is the script in TilesController:

onready var tile = preload("res://scenes/Tile.tscn")
#tile used to preload another scene before ready

func _spawn_tiles(words: String, textCount: int, wordListArray: Array):
	#function to spawn tiles with letters initialized
	for i in textCount:
		var tileInstance = tile.instance()
		tileInstance._set_property(words[i], i)
func _on_entered_tile(idx: int):
	#function to be called by input_entered signal to update line points
	if GameController.currentLevel == 1 and GameController.currentCategory == 1:
		get_node("../Sprite").visible = false

func _on_exited_tile():
	#function to be called by input_exited signal to update line points
	var correct = false
	var startIdxSlot = 0
	var selectedText
	for i in range(wordList.size()):
		if not wordList[i] == get_node("../Label").text:
			startIdxSlot += str(wordList[i]).length()
			correct = true
			selectedText = wordList[i]
			for j in range(wordRemain.size()):
				if wordRemain[j] == selectedText:

The Tree:

--TilesController(script here)

asetyowatir | 2020-10-23 14:16

:bust_in_silhouette: Reply From: doogragdaba

Thank you for all the help! It turned out to be another bit of my code that was acting up and preventing the collision from registering… Spent way too much time on this, but definitely learned signals. Thanks again!