Instances of scene sharing signal calls

Godot Version

4

Question

Ive been trying to create a scene that is interactable by the player when they are near it. So far that has been great, using an area 2d I have a popup when the player gets close to the button that tells them to interact. However I’ve noticed that if I put two buttons out they both will preform an action when i press only one of them. I had looked this up and found that the script/cube meshes should be local to the scene but that didnt work and still had both buttons pressing at the same time.

extends Area3D

@onready var ui  =  %UICanvas
@onready var mesh = $MeshInstance3D

@export var text = "Press E to Interact"
@export var normColor = Color(0.80784314870834, 0, 0.05098039284348)
@export var pressColor: Color

@onready var WallSpot : Node3D = $Node3D

signal on_interact

func _input(event):
	if event.is_action_released("Interact"):
		print("Worked!!")
		on_interact.emit()
		do_color()
		

func do_color():
	var mat = mesh.get_active_material(0)
	mat.albedo_color = pressColor
	await get_tree().create_timer(0.5).timeout
	mat.albedo_color = normColor
	

func _on_body_entered(body):
	ui.update_labl(text, true)


func _on_body_exited(body):
	ui.update_labl("", false)


func _on_on_interact():
	print("Signal Received!")
	
	var wall = load("res://Prefabs/cube.tscn") as PackedScene
	var wallInstance = wall.instantiate() as StaticBody3D
	
	self.add_child(wallInstance)
	wallInstance.global_position = WallSpot.global_position
	wallInstance.scale = Vector3(3,5,8)
	wallInstance.rotation = WallSpot.rotation

Above is the code of the button and ill paste a screenshot of the setup of the button scene below.

For the moment in an attempt to fix the issue I attempted to signal the interact button to itself hoping it would only trigger the one button but that also didn’t work out. I’ve added the picture below, the red boxes are the areas to interact with, I am only in one of them so the other shouldn’t have a wall too.

I guess the problem is that in your _input function you are not checking whether you are inside area. Try to add bool variable on top of your script, like:

var inside_area: bool = false

And then change your _on_body_entered and _on_body_exited functions to modify the inside_area value. Also add a check inside _input:

func _input(event):
	if inside_area:
		if event.is_action_released("Interact"):
			print("Worked!!")
			on_interact.emit()
			do_color()
func _on_body_entered(body):
	inside_area = true
	ui.update_labl(text, true)

func _on_body_exited(body):
	inside_area = false
	ui.update_labl("", false)

I cant believe I hadn’t seen that thank you, marking this as solution