Topic was automatically imported from the old Question2Answer platform.
Asked By
ashish
I having trouble disabling the _process(delta) function.
I know that we have a method set_process(false), but somehow I am not able to disable the process(delta) function by calling this method from another function. Whatever function is being executed keeps getting executed over and over again despite a call to set_process(false) method. If I set an if condition and call this method within the if block, it doesn’t work, even when the if condition becomes true.
What am I doing wrong?
Can someone please give an example of how to enable and disable the _process(delta) function?
As you said yourself, set_process(false)is disabling virtual _process() function and should work very straightforward.
There could be a number of reasons why it is not working for you. Maybe you’re calling it for wrong node, maybe you’re not calling it at all.
But guessing is a wrong approach in programming. Use debugger to see what’s exactly going on. Post your code here (a minimal example that reproduces an issue).
Five years later, I’m having a similar issue with Godot 4.3 and a _physics_process(delta) function. Found a solution which seems to also work for the _process(delta) function and thought someone might still find it useful.
In my use case I have a _physics_process(delta) function and I wanna have it start/stop running along with a Timer, so that as the timer ticks I can update a progress bar. To do this, when I run timer.start() I also run set_physics_process(true), then I use values from my Timer on my _physics_process(delta) function, and when the Timer emits a timeout signal I run set_physics_process(false) to stop these calculations which use Timer values (I’m using the ConnectFlags.CONNECT_ONE_SHOT parameter to ensure this runs only once per timer cycle, but I don’t think that’s relevant here).
At first this didn’t work for me: set_physics_process(true) seemed to work fine, but set_physics_process(false) would not stop my _physics_process(delta) function from running every tick. Then I read the docs for the set_physics_process and realised that (as per the docs) If _process() [or _physics_process()] is overridden, this will be automatically enabled before _ready() is called.
So I declared a _ready() function on my scene and just called set_physics_process(false) within it. What that does is it stops this automatic behavior as early as possible, enabling me to have full control over when the _physics_process(delta) function runs. So, by doing this, all my calls to set_physics_process() seem to be working just fine.