I'm obviously new to Godot and scripting and am reading the GDscript guide/style guide. I see some functions begin with the underscore character and some don't. I'm just curious why? I'd like to get it straight before I get to deep into things. Thanks for the help.
Why do some functions names start with "_" and some don't?
- Edited
Going to guess that functions with at the start are meant to be overridden when defined and are to be thought of as private (like Node.process() or Object._get()), while the others are meant to be called explicitly and seen "publicly".
- Edited
Callbacks generally begin with an underscore. A callback is a function which the engine calls at specific points. For example, _ready()
is called once all of a node's children are loaded and ready (or immediately upon being loaded, if it has no children.) Other callbacks include _input(event)
, _process(delta)
, and _physics_process(delta)
Functions that are connected to signals are a type of callback, and might have a name like _on_button_pressed()
It can also indicate that a function is meant to be used only within that script, as GDScript has no concept of encapsulation (outside of needing a reference to the node, I suppose.) So if you want to discourage calling _my_private_function()
, give it an underscore at the start.
@SolarLune , @Somnivore , thanks I appreciate the answers.