mouse isn't captured

Godot Version

v4.2.1.stable.official [b09f793f5]

Question

i made a camera script which captures the mouse and rotates the head for movement it used to work but now suddenly doesnt
script is

extends Node3D

var sens = 0.005

func _ready():
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _input(event: InputEvent) -> void:
	if event is InputEventMouseMotion:
		get_parent().rotate_y(-event.relative.x*sens)
		rotate_x(-event.relative.y*sens)
		rotation.x=clamp(rotation.x, deg_to_rad(-75, deg_to_rad(60))

Try setting up a button that can toggle mousemode on or off.

My guess is either the ready function happens at an bad time now. Or there is some other code after that ready function changing the capture mode. Or something happening to the OS.

func _unhandled_input(event: InputEvent): 
	if event is InputEventMouseButton:
		Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
	elif event.is_action_pressed("ui_cancel"):
		Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
	if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
#just put your camera movement stuff here and you should be good to go

tried this doesn’t work for me

did you add a canvas layer, or something to with a hud?