ConfirmationDialog node not adding to scene despite being added to the scene

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

I am using Godot to create a desktop application called OCSM and am in the process of upgrading it from v3.5 to v4.0. Currently, all of my scripts are in C#.

I have had the application set up to intercept what is now the NotificationWMCloseRequest notification in order to show a custom popup prompting the user to confirm that they indeed want to close the application. In keeping with that, I set up the File->Quit menu item of my main menu to use GetTree().Root.PropagateNotification() to trigger this process. This was working just fine in v3.5, both via the Quit menu item and using the OS window controls to attempt to close the window.

Now in v4.0 I am experiencing some very strange behavior that I can’t figure out. Firstly, when clicking the OS window “close window” button the confirmation dialog pops up like normal and functions correctly. However, when clicking the Quit menu item the confirmation dialog never pops up.

I did some debugging and discovered that, at least according to my GD.Print’s, the node is getting added to the tree where it should be being added. However, using the editor’s Remote node tree view, I can see that when clicking the Quit menu item the confirmation dialog node is not actually getting added to the tree even though, in the script, it thinks it has been. I do see it being added normally when attempting to close the window.

I am using an Autoload Node to listen for and handle this notification, so that may be pertinent. Here is the code for where I am generating and adding the node:


using Godot;

namespace OCSM.Nodes.Autoload
{
	public partial class AppManager : Node
	{
		public bool IsQuitting { get; set; } = false;
		
		public override void _Notification(int notificationCode)
		{
			switch((long)notificationCode)
			{
				case NotificationWMCloseRequest:
					showQuitConfirm();
					break;
			}
		}
		
		public override void _Ready()
		{
			GetTree().AutoAcceptQuit = false;
		}
		
		private void showQuitConfirm()
		{
			if(!IsQuitting)
			{
				var resource = ResourceLoader.Load(Constants.Scene.ConfirmQuit);
				var confirmQuit = resource.Instantiate();
				GetTree().CurrentScene.AddChild(confirmQuit);
				confirmQuit.PopupCentered();
				GD.Print("What is the current scene? ", GetTree().CurrentScene.Name, " confirmQuit parent? ", confirmQuit.GetParent(), " Is confirmQuit visible? ", confirmQuit.Visible);
				IsQuitting = true;
			}
		}
	}
}

And some sample output from that GD.Print line:


What is the current scene? AppRoot confirmQuit parent?  Is confirmQuit visible? True
What is the current scene? AppRoot confirmQuit parent?  Is confirmQuit visible? True

The first output line is from using the Quit menu item. The second output is from using the OS close window button.

At this point, I’m kind of at my wits’ end. The node is either not actually being added to the node tree or maybe it’s being removed from the node tree so fast that it doesn’t have a chance to actually draw in the UI. I’ll admit the codebase for this project is… fairly extensive so far, so there’s always the possibility that it’s a weird confluence of small things that I’ve missed. If you’ve got the time or inclination, you can check out the full source for the project here: https://github.com/nemesisx00/ocsm

I should probably stress here that the rest of the upgrade process has been relatively straightforward, if not outright easy. I am extremely pleased with v4.0 overall, especially the transition to .NET 6. So far this Quit menu item bug is the only functional problem I’ve run into.

In any case, I’d appreciate some help figuring out what’s going on.