Halt Godot Execution

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

I’m writing some code in c# and I just want to stop code execution for about half a second. This would be in the middle of functionality and I don’t care at all about freezing the game or making it behave unresponsively, (although if avoiding making the os realises it’s unresponsive can be avoided that would be good but not necessary).

So i tried a couple of things and it just doesn’t seem to pause the game and I was wondering why this was, for example if I have a little code snippet like

GD.Print("start waiting");
OS.delay_msec (500);
GD.Print("stop waiting");

that kind of general structure but there was no discernible delay between “start waiting” and “stop waiting” being printed.
I also tried some other things such as

System.Threading.Thread.Sleep(500);

again no luck and I was wondering why this was and how I could fix it.

Why do you need to halt execution at first place? There are plenty ways to freeze main process, but optimal solution is heavily dependent on your reason why you need it.

AlexTheRegent | 2021-10-08 14:44

Atm it’s just so I can visualise the processing of a function easier for debugging. So that I can do something, pause so I can see the effect of what has been done, do something else, and easier see where the issue is.
This is also why ideally I want the code to be as short as possible, ideally one line so I don’t pollute the function I’m trying to debug.

slit-bodmod | 2021-10-08 16:28

Hello, for this use case you could put a breakpoint and go step by step using the debugger (“step into” button).
For convenience you can temporarly enable the “always on top” option in the settings which let you click on the editor to step a frame without your game going in the background.

Lola | 2021-10-08 17:11

Ah ok, so with the debugger how would I use a break point, press the red circle in vs code to add one to a specific line and will the code automatically stop before/after that line executes when I click run (or scene run in my case)?

slit-bodmod | 2021-10-08 17:25

Oh I hadn’t realized you were not using GDScript, sorry :confused:
I’m not familiar with godot+c# but this is how it would work in gdscript.

Lola | 2021-10-09 06:37