Godot Version
4.6.1
Question
Hi,
while learning godot andd GDScript, I discovered that when you are not using the delta parameter of the:
func _process(delta: float) → void:
or
func _physics_process(delta: float) → void:
you can write and underscore “_” in front of delta, like “_delta” to avoid godot debugger to raise a warning that parameter is not used in the function.
My understanding is that it’s more a naming convention relative to debugger, to ignore variables starting with “_”.
- Am I correct ?
- what if, somewhere else in the code, I have some variables starting with “_”"? Will they be also ignore by debugger ? which is wrong in this case.
usually variables starting with ”_” are internal/private variables.
thx.
1 Like
It is just a naming convention for the warning, and it is just a warning. Both are of little concern by the time the game is running.
It’s good to catch unused variables where possible, less overhead if removed. But at the same time some functions must match a signature, so delta cannot be removed and still override _process; furthermore the @warning_ignore("unused_function_variable") is a little long, and would be difficult to apply to some function parameters and not others. Thus the short leading _ denotes a required variable that isn’t used in this function, but may have been or will be used in an override.
2 Likes
No, you are not correct. The convention is to not warn for unused function arguments. The variable still exists and can be used.
No. That’s only for function arguments.
Yes, but only by convention. Prepending a variable or function with an underscore indicates you shouldn’t use it outside the class/function. In practice, all variables and functions are always public. They can be “mis-used.” You have to police yourself.
1 Like