Many IDEs like IntelliJ let you set “watches” to track the value of an expression that isn’t explicitly defined as a variable in the code. In Godot, the closest thing I’ve found is looking at the remote tree, but that only shows you the properties of a node. What if I want to evaluate an expression like position.distance_to(neighbour.position) during runtime, without printing it out, to avoid a bunch of print statement I will have to remember to delete later?
I am wondering if this is a feature that exists in the Godot IDE and I just missed it, or if it’s not a thing at all.
If you use C#, this can easily be achieved with any external IDE you use.
If you use GDScript though, I find that simply watching Remote is plenty enough in most cases, and if I need to evaluate an expression somewhere, I can simply set a breakpoint in a more critical part of the code, maybe inside a logic statement to check my expression. And breakpoints, of course, support stepping through the code while execution is paused.
That’s unfortunate, because I want to evaluate the value of an expression as the game is executing, like you would if you were to print it out in _physics_process() or something. I just don’t want the extraneous print statements.
I suppose a simple solution would be to create a singleton which draws some variables on the screen that you are trying to watch, using a label or a text field. That way you don’t have to fill up the output with print statements.
But anyway, VS Code’s Watch window is working well, on (VS Code, not Godot native) breakpoint only, though (for live variable watch, better display them on screen with some visual debugger like Debug Draw 3D addon).
Another potential workaround is to hoist local variables to class variables so you can see them in the remote tree view. I realise this isn’t ideal and you’d probably want to clean them up later, so doesn’t solve that problem. However, I do generally find this nicer than print statements, so thought I’d mention.
var _distance_to_neighbour
func _physics_process():
_distance_to_neighbour = position.distance_to(neighbour.position)