After reading the Quit() wait for the last iteration of the loop , but in my case what i do is using states
and when user press quit
State QuitState.HandleInput(Player player, InputEvent inputEvent)
{
if (inputEvent.IsActionPressed(StateInput.quit.ToString()))
{
player.GetTree().Quit();
return this;
}
return null;
}
In the player class, I expect that when player.GetTree().Quit() is invoked, it will completely quit the game window and properly shut down all Godot systems. However, what actually happens is that it invokes the quit, but the game still gets caught in the _PhysicsProcess(double delta) method where I check the state.
//Here invoke the quit state
public override void _Input(InputEvent @event)
{
if (@event.IsPressed())
{
CurrentState = CurrentState.HandleInput(this, @event);
}
}
.
.
.
// CurrentState is null here after invoking the player.GetTree().Quit();
public override void _PhysicsProcess(double delta)
{
if (CurrentState.GetInput() == StateInput.free_look)
{
}
}
My question is what is the proper way to quit in such scenario ?
Thanks
None of those are loops, so there’s something else going on you’re not showing. Add a breakpoint to your quit() call and follow execution until you find where it actually gets stuck, please.
No i think you are wrong ,
_PhysicsProcess is game loop . looks like the _PhysicsProcess is not quitting …
After i send Quit command ,
now im sending :
You think I am wrong, but I am, in fact, not wrong and know what I am talking about. <3
If you are not trapping your own code in an endless loop, then the quit procedure happens without further issues, by sending the appropriate notifications and destroying objects in order, until the engine can destroy the main window, thread, and return to the system thread, ending the process.
The behaviour you are seeing means you caused a dead loop in your code somehow, but because you are not providing enough information, all I can tell you is to use breakpoints to figure out where this happens.
The fact that you are adding a notification to the root tells me you are either forking your thread improperly somehow or discarding notifications you shouldn’t somewhere, but I am not a fortune teller, you have to tell me what your code does (as in, pasting the actual code or a link to the project files) or we’re gonna be here for a long time.