What is the difference between delta and _delta in the _physics_process argument field?

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

I have been following the documentation and setting up some simple movement code. In the documentation _physics_process(delta) is used, which seems to work fine, but Godot flags an error:

W 0:00:00.538 The argument ‘delta’ is never used in the function ‘_physics_process’. If this is intended, prefix it with an underscore: ‘_delta’

The documentation doesn’t seem to mention _delta, or what the difference is here. Can anyone explain?


:bust_in_silhouette: Reply From: kidscancode

There is no difference, it’s just a variable name. You could change it to anything you wanted and it would still work the same.

The point of that message is that it is letting you know you’re not using an argument that was passed to the function. That may be fine - it’s just a warning.

However, the warning system will ignore arguments whose names start with _. So if you don’t plan to use the delta value, you can rename it to _delta and the warning will go away.

Thanks for the reply!

Using move_and_slide() which I understand automatically uses delta, within physics_process - is it necessary to include delta as an argument?

eg. _physics_process() vs _physics_process(delta)

Also just to confirm, if it is necessary to declare it, does using _delta only affect the warning system and not the functionality of the code?

Heathy | 2021-07-30 14:51

You can’t just write

func _physics_process():

Because the engine calls the function and passes the parameter. You’ll get an error, it’s not optional.

And yes, the name of the argument doesn’t change anything. it’s a variable. You can write:

func _physics_process(bananas):

And now bananas will have the value of the frame time that the engine passes to the function.

kidscancode | 2021-07-30 16:42