Issues with Signals

Godot Version

4.3.3

Question

I am trying to create a BuildingManager global autoload which will handle everything concerning the building of things in my game. Now I don’t know whether the issue is that this is an autoload or something else but the script below works in detecting but it detects the wrong thing and I don’t have a clue why.

func SpawnObject(obj):
	if current_spawnable != null: # we check if we already have an object spawned 
		current_spawnable.queue_free() # destroy it so we don't have multiple objects above each other
	current_spawnable = obj.instantiate()
	#get_tree().root.add_child(current_spawnable)  # add it to the tree ( we can change it to a node holder )
	get_tree().root.get_node("MainScene/GameScene/LevelPlaceholder/Level01/Towers").add_child(current_spawnable)
	current_spawnable.set_name("BalistaTower")
	
	var tower_body_area = current_spawnable.get_node("TowerBodyArea") as Area2D
	tower_body_area.connect("body_entered", Callable(self, "_on_Tower_Body_Entered"))
	tower_body_area.connect("body_exited", Callable(self, "_on_Tower_Body_Exited"))
	
	GameManager.game_state = GameManager.GameState.BUILDING
	
func ClearSpawnObject():
	current_spawnable.queue_free()
	current_spawnable = null
	GameManager.game_state = GameManager.GameState.IN_GAME
	
# ==================================================================================================
#	Collision Check
# ==================================================================================================
func _on_Tower_Body_Entered(body):
	print("ENTERED")
	ableToBuild = false
	
func _on_Tower_Body_Exited(body):
	ableToBuild = true
	print("EXITED")

It detects instead of my towers that I have here

var tower_body_area = current_spawnable.get_node("TowerBodyArea") as Area2D

it somehow detects the Enemies that are spawned which I checked the signals and there werent any with the name. Plus I have it added above so it should get the node that is the TowerBodyArea. The enemy just has a HurtBoxComponent.

Screenshot_2

and in the tower script I have this bit of code to detect the Enemies but I don’t think that this would be the issue?

func _on_range_body_entered(body) -> void:
	if body.is_in_group("Enemy"):
		enemies.append(body.get_parent()) # body is the Beetle / Parent is the pathfollow 2d

func _on_range_body_exited(body) -> void:
	if body.is_in_group("Enemy"):
		enemies.erase(body.get_parent()) # body is the Beetle / Parent is the pathfollow 2d

Any ideas are welcome on which could be the issue since I have been looking for a solution for a couple of hours now and will still search for that as well.

Okay I finally found the root of my issues… It seems it’s not due to the signals but it turned out that it was due to the Collision layers. It was staring me in the face and I didn’t notice that. Setup the collision layers to all of the actors and it works quite perfectly.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.