Godot Version
Godot 4.2.2
Question
Hello! I was making a tile-based building system and I was trying to make an area detection so that you couldn’t place building if there already was one, but i get this error “Attempt to call function “get_overlapping_areas” in base “null instance” on a null instance.”
The code I tried was:
if $Area2d.get_overlapping_areas().size() > 0:
$Deny.show()
$Ok.hide()
else:
$Ok.show()
$Deny.hide()
And here is the full code I am using for building:
func _process(delta):
var mouse_tile = Global.tilemap.local_to_map(get_global_mouse_position())
var local_pos = Global.tilemap.map_to_local(mouse_tile)
var world_pos = Global.tilemap.to_global(local_pos)
global_position = world_pos
if $Area.get_overlapping_areas().size() > 0:
$Deny.show()
$Ok.hide()
else:
$Ok.show()
$Deny.hide()
func _unhandled_input(event):
if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_LEFT:
set_process(false)
set_process_unhandled_input(false)
$Ok.hide()
$Deny.hide()