is there a function that doesn't call every frame?

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

so I have been using Godot for a while, but what I realized is that "func _process(delta) calls every frame. fyi, i use it alot, do you think that lowers performance?.

for example:

var cat = true

func _process(delta):
if cat = true
do something

so basically, instead of doing something every frame, is there a way to do it when I want?

:bust_in_silhouette: Reply From: Ertain

There are functions (i.e. callbacks) which are called when necessary. There’s the callback function _input() which is called when there’s an input event. Then there are the signals from common nodes and ones that are implemented. Finally (at least what I know about), there’s Godot notifications, which are implemented by every class in the engine which inherits from Object.

Hope this helps.

:bust_in_silhouette: Reply From: skysphr

Pretty much no functions other than _process() and _physics_process() are called continuously. The general rule of thumb is that _physics_process() should be used for time critical operations that should never be affected by lag, as the function runs on a separate thread and its frequency is constant (you can set the physics fps in project settings). So you should not throw heavy calculations at _physics_process(). On the other hand, _process() is fine but it tries to run as fast as possible and hence it is prone to frequency fluctuations.

As Ertain mentioned, use signals and notifications when appropriate, timers and tweens for delays and simple animations, and animation players for when you want to orchestrate a timeline of events.