Godot Version
4.4.1
Question
` I’ve tried to use unhandled inputs and to an extent it works. When I’m in the options menu which is another scene I can still click on the map which is behind the options screen and move my character which I don’t want. I’ve set up a simple print function which works and shows when i click and don’t click on the map but the whole disabling doesn’t work. Idk why I want some help please
extends Node2D
@onready var tile_map: TileMapLayer = $"../TileMap"
@onready var sprite_2d: Sprite2D = $CharacterBody2D/Sprite2D
@onready var animation_player: AnimationPlayer = $CharacterBody2D/AnimationPlayer
@onready var animation_tree: AnimationTree = $CharacterBody2D/AnimationTree
@onready var options_in: Button = $Options/Options_in
var astar_grid: AStarGrid2D
var current_id_path: Array[Vector2i]
var current_point_path: PackedVector2Array
var target_position: Vector2
var char_moving: bool
var direction: Vector2
var options_screen: Node = null
var map_input_enabled : bool= true
func _unhandled_input(event):
if not map_input_enabled:
return
if event is InputEventMouseButton and event.pressed:
print("Clicked on map")
func _ready():
animation_tree.active = true
astar_grid = AStarGrid2D.new()
astar_grid.region = tile_map.get_used_rect()
astar_grid.cell_size = Vector2(32, 32)
astar_grid.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_NEVER
astar_grid.update()
for x in tile_map.get_used_rect().size.x:
for y in tile_map.get_used_rect().size.y:
var tile_position = Vector2i(
x+tile_map.get_used_rect().position.x,
y+tile_map.get_used_rect().position.y
)
var tile_data = tile_map.get_cell_tile_data(tile_position)
if tile_position == null or tile_data.get_custom_data("Walkable") == false:
astar_grid.set_point_solid(tile_position)
target_position = Vector2(16,16)
if global_position == target_position:
direction = Vector2(0,-1)
animation_tree["parameters/conditions/idle"] = true
animation_tree["parameters/conditions/is_moving"] = false
animation_tree["parameters/idle/blend_position"] = direction
func _process(_delta):
update_animation_parameters()
func _input(event):
if event.is_action_pressed("move") == false:
return
var id_path
if char_moving:
id_path = astar_grid.get_id_path(
tile_map.local_to_map(target_position),
tile_map.local_to_map(get_global_mouse_position())
)
else:
id_path = astar_grid.get_id_path(
tile_map.local_to_map(global_position),
tile_map.local_to_map(get_global_mouse_position())
)
if id_path.is_empty() == false:
current_id_path = id_path
current_point_path = astar_grid.get_point_path(
tile_map.local_to_map(target_position),
tile_map.local_to_map(get_global_mouse_position())
)
for i in current_id_path.size():
current_point_path[i] = current_point_path[i] + Vector2(16, 16)
func _physics_process(_delta: float) -> void:
if current_id_path.is_empty():
return
if char_moving == false:
target_position = tile_map.map_to_local(current_id_path.front())
char_moving = true
global_position = global_position.move_toward(target_position, 1)
if global_position == target_position:
current_id_path.pop_front()
if current_id_path.is_empty() == false:
target_position = tile_map.map_to_local(current_id_path.front())
else:
char_moving = false
var walking_direction = target_position - global_position
if (abs(walking_direction.x) > abs(walking_direction.y)):
if walking_direction.x > 0:
direction = Vector2(1,0)
else:
direction = Vector2(-1,0)
else:
if walking_direction.y > 0:
direction = Vector2(0,-1)
else:
direction = Vector2(0,1)
func _on_options_in_pressed() -> void:
if not is_instance_valid(options_screen):
options_screen = load("res://Options_screen.tscn").instantiate()
add_child(options_screen)
options_screen.connect("tree_exited", Callable(self, "_on_options_closed"))
options_in.visible = false
map_input_enabled = false
func _on_options_closed():
map_input_enabled = true
options_in.visible = true
options_screen = null
`