Why is this statement not printed?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JokerSimpers

This is a simple code maintaining movement of the character, if I press Esc, the debbuger closes. I added print(“done”) but it gets printed occasionally. What is going on? I thought _physics_process() is like a loop iterating over and over, so why is my “done” printed so barely?

extends CharacterBody3D

@onready var camera = $Camera3D

const SPEED = 10
const JUMP_VELOCITY = 18
const GRAVITY = 90

var sens = 0.009

func _ready():

func _input(event):
if event is InputEventMouseMotion:
var movement = event.relative
camera.rotation.x += -movement.y * sens
camera.rotation.x = clamp(camera.rotation.x, -1, 1)
rotation.y += -movement.x * sens

func _physics_process(delta):
if Input.is_key_pressed(KEY_ESCAPE):

var inputDir = Input.get_vector("left", "right", "forward", "back")
var direction = (transform.basis * Vector3(inputDir.x, 0, inputDir.y)).normalized()
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED

if Input.is_action_just_pressed("jump") and is_on_floor():
	velocity.y = JUMP_VELOCITY
if not is_on_floor():
	velocity.y -= GRAVITY * delta 


*Bonus question - why does that chunk of code (just those lines for quitting the debugger) is not working in an _input(event) function? I had to put it in _physics_process.

**Bonus question #2 - I was not able to figure out how to add image into this text… so, sorry for that long code :smiley: I guess I cannot upload pictures other than using URL or?

:bust_in_silhouette: Reply From: deaton64

Try it in a _process function as that runs every frame.

Bonus 1:
Did you do your _input(event) like this:

taken from the docs

func _input(event):
    if event is InputEventKey and event.pressed:
        if event.scancode == KEY_T:
            print("T was pressed")

Bonus 2:
Upload you image to something like https://imgur.com/ and link off it.

Hey, thank you for answers. I tried to play with it a bit but nothing really worked. After all I put that in _unhandled_input(event)

func _unhandled_input(event):

if Input.is_action_just_pressed(“exit”):


Still, print(“done”) happens about 50 % of the time. I dont know, maybe it is related with get_tree().quit() and the loop is not necessarily top → down order.

JokerSimpers | 2022-10-25 10:39