0 votes

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.

in Engine by (14 points)

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.

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.

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.

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)?

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

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.